error LNK2001: unresolved external symbol clock() - c

I have added #include in component.c file and created variables with clock_t type and clock(), which is compiling successfully.
clock_t start_t, end_t, total_t;
start_t = clock();
When i build the driver file(.sys) there is a linker which tries to find clock() but it cannot find and throws error.
component.lib(comp.obj) : error LNK2001: unresolved external symbol clock
driver.sys : fatal error LNK1120: 1 unresolved externals
I have tried reading other solutions for similar linker error.
Most of them has mentioned about Microsoft visual c++ compiler.
clock_t start_t, end_t, total_t;
start_t = clock();
I have tried adding extern in the component.c file. But it doesn't help.
extern clock(void);

Related

LINK2019 unresolved external symbol _time64

foo.exe depends on bar.lib
source.c in bar.lib:
#include <time.h>
void func()
{
time_t now = time(NULL);
... // use 'now'
}
Bar.lib can be generated. However, foo.exe's linking process will report an error:
LINK2019
unresolved external symbol '_time64' referenced in function 'time'.
foo
bar.lib(source.obj)
What may cause this?

link error in gsl_complex_mul

I have started using gsl recenltly in a huge old C project. I have managed to add the libraries by adding the location in my system in Properties>C/C++>General>Additional Include Directories.
In my code, I am also including the following:
#include "gsl/gsl_matrix.h"
#include "gsl/gsl_matrix_complex_double.h"
#include "gsl/gsl_matrix_complex_float.h"
#include "gsl/gsl_matrix_complex_long_double.h"
#include "gsl/gsl_math.h"
#include "gsl/gsl_spmatrix.h"
#include "gsl/gsl_complex.h"
#include "gsl/gsl_complex_math.h"
#include "gsl/gsl_inline.h"
#include "gsl/gsl_complex.h"
I can now use most functions of gsl. but in the fowllowing function:
void vector_complex_mul_elements(gsl_vector_complex *v1, gsl_vector_complex *v2)
{
gsl_complex cpx1, cpx2, cpx3;
GSL_SET_COMPLEX(&cpx1, 0, 0);
GSL_SET_COMPLEX(&cpx2, 0, 0);
GSL_SET_COMPLEX(&cpx3, 0, 0);
if(v1->size != v2->size)
{
printf("Error: Lenght of arrays do not match.\n");
return;
}
for(i=0; i < v1->size; i++)
{
cpx1 = gsl_vector_complex_get(v1, i);
cpx2 = gsl_vector_complex_get(v2, i);
//cpx3 = gsl_complex_mul(cpx1 , cpx2);
gsl_vector_complex_set(v1, i, cpx3);
}
}
When I uncomment the line:
cpx3 = gsl_complex_mul(cpx1 , cpx2);
I get the following errors:
Error LNK2001: Unresolved external symbol "_log1p".
Error LNK2001: Unresolved external symbol "_log1p".
Error LNK2001: Unresolved external symbol "_hypot".
Error LNK1120: 2 unresolved external references.
I have already tried writing it like:
gsl_vector_complex_set(v1, i, gsl_complex_mul(cpx1 , cpx2));
Then I get these errors:
Error LNK2019: Reference to unresolved external symbol "_log1p" in function "_gsl_complex_logabs".
Error LNK2019: Reference to unresolved external symbol "_hypot" in function "_gsl_complex_div".
Error LNK2001: Unresolved external symbol "_log1p".
Error LNK1120: 2 unresolved external references.
Is this a only a linking problem or the way I am using it is wrong?
These (lop1p and hypot) functions are in the standard maths library. Are you including math.h and linking to it (-lm)? As per the GSL documentation.
It seems to me that you are wrong linked GSL library.
Try to rebuild GSL as a dll and relink it, as I showed you in your other post.

Open .mat files in C

I'm trying to write a C script able to open .mat files. The .mat files were written in Matlab 2015b 64-bit version. I'm using Visual Studio 2010 to compile the code. Here it is:
#include <stdio.h> /*Std library*/
#include "..\matlablib\mat.h" /*provided by MathWorks*/
int main(){
MATFile * pMF;
printf("Abrindo arquivo .mat...\n"); /*check (1)*/
pMF = matOpen("teste.mat","r");
printf("Arquivo .mat aberto.\n"); /*check (2)*/
getch();
}
As I compile this, I get the following message error:
matread.obj : error LNK2019: unresolved external symbol _matOpen
referenced in function _main
matread.exe : fatal error LNK1120: 1 unresolved externals
Have anyone had a similar problem before?
Thanks in advance,
Porto

C extern clock_t variables not working as expected in file; [duplicate]

This question already has answers here:
How to correctly use the extern keyword in C
(10 answers)
Closed 6 years ago.
So I have, 3 files; main.c , file.c file.h
in file.h I declared 3 variables
extern clock_t start_t, end_t, total_t;
in file.c I wrote a function to save the length of time of main running program;
and in file.h I reference it as "void saveLog(void);"
void saveLog(void)
{
end_t = clock();
total_t = (end_t - start_t);
double time_spent = (double) total_t / CLOCKS_PER_SEC;
double *arr = malloc(sizeof(double));
*arr = time_spent;
FILE* fp = fopen("log.txt","wb");
if (fp)
{
printf("Elapsed: %f seconds\n", (double) time_spent);
fwrite(arr, 1, sizeof(double), fp);
fclose(fp);
}
}
in main.c at the start of main I wrote start_t = clock();
and at the end wrote atexit(savelog)
I included all libraries (time.h , stdlib.h , stdio.h in all files)
When compiling I get the error apple linker id error
Undefined symbols for architecture x86_64:
"_end_t", referenced from:
_saveLog in file.o
"_start_t", referenced from:
_check_answer in main.o
_saveLog in file.o
"_total_t", referenced from:
_saveLog in file.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
By the way my thinking is , to begin counting clock and the start of main and simply do the math in the function.
My question is ,why does it not work? How else should I use the clock_t variables? I tried some testing with int's and the seemed to be referenced just fine.
I found out what I was missing; I forgot to define the variables in the file that contains main() (though any other source file could define them instead, as long as only one file defines them and the object code for that file is linked when the program is linked).

LNK1120, LNK2001, LNK2019 - Can't track down the reason

I have no idea what the problem is. I am trying to build my project for release but the linker complains about not finding external symbols.
The thing that's odd is that I copy & pasted all include paths and dependencies from the Debug into the Release build configuration and double checked it.
get_PC_definition() is e.g. declared in cpudefs.h:
/* Return register definition of instruction pointer */
extern RegisterDefinition * get_PC_definition(Context * ctx);
There are a few implementations of this function - which one I chose is controled by macros so yes, I defined all necessary macros too:
RegisterDefinition * get_PC_definition(Context * ctx) {
static RegisterDefinition * reg_def = NULL;
if (!context_has_state(ctx))
return NULL;
// and so on ..
return reg_def;
}
cpudefs.obj gets build so far but the Linker just mocks around .. maybe I am already blind to the error but like I said, I copied the configurations from the Debug into the Release build configuration.
Any ideas what I could try?
Error output:
Error 43 error LNK1120: 9 unresolved externals C:\svn\AgentSib\Release\agentsib.exe agentsib
Error 31 error LNK2001: unresolved external symbol _get_PC_definition C:\svn\AgentSib\AgentSib\registers.obj agentsib
Error 32 error LNK2001: unresolved external symbol _get_PC_definition C:\svn\AgentSib\AgentSib\runctrl.obj agentsib
Error 34 error LNK2001: unresolved external symbol _get_PC_definition C:\svn\AgentSib\AgentSib\symbols_cdb.obj agentsib
Error 35 error LNK2001: unresolved external symbol _get_PC_definition C:\svn\AgentSib\AgentSib\cpudefs.obj agentsib
Error 36 error LNK2001: unresolved external symbol _get_PC_definition C:\svn\AgentSib\AgentSib\expressions.obj agentsib
Error 37 error LNK2001: unresolved external symbol _get_PC_definition C:\svn\AgentSib\AgentSib\funccall.obj agentsib
Error 38 error LNK2001: unresolved external symbol _get_PC_definition C:\svn\AgentSib\AgentSib\profiler_sst.obj agentsib
Error 41 error LNK2019: unresolved external symbol _BREAK_INST referenced in function _get_break_instruction C:\svn\AgentSib\AgentSib\cpudefs.obj agentsib
Error 27 error LNK2019: unresolved external symbol _cpu_bp_get_capabilities referenced in function _context_get_supported_bp_access_types C:\svn\AgentSib\AgentSib\context-sib.obj agentsib
Error 30 error LNK2019: unresolved external symbol _cpu_bp_on_resume referenced in function _sib_resume C:\svn\AgentSib\AgentSib\context-sib.obj agentsib
Error 28 error LNK2019: unresolved external symbol _cpu_bp_plant referenced in function _context_plant_breakpoint C:\svn\AgentSib\AgentSib\context-sib.obj agentsib
Error 29 error LNK2019: unresolved external symbol _cpu_bp_remove referenced in function _context_unplant_breakpoint C:\svn\AgentSib\AgentSib\context-sib.obj agentsib
Error 42 error LNK2019: unresolved external symbol _crawl_stack_frame referenced in function _trace_stack C:\svn\AgentSib\AgentSib\stacktrace.obj agentsib
Error 33 error LNK2019: unresolved external symbol _get_PC_definition referenced in function _command_get_children_cache_client C:\svn\AgentSib\AgentSib\stacktrace.obj agentsib
Error 39 error LNK2019: unresolved external symbol _ini_cpudefs_mdep referenced in function _ini_cpudefs C:\svn\AgentSib\AgentSib\cpudefs.obj agentsib
Error 40 error LNK2019: unresolved external symbol _regs_index referenced in function _get_reg_by_dwarf_id C:\svn\AgentSib\AgentSib\cpudefs.obj agentsib
Edit:
Calling function get_PC_definition()
static int set_debug_regs(Context * ctx, int check_ip, int * step_over_hw_bp) {
int i;
int ret;
uint32_t dr7 = 0;
ContextAddress ip = 0;
ContextExtensioni8051 * dext = EXT(ctx);
ContextExtensioni8051 * bps = EXT(context_get_group(ctx, CONTEXT_GROUP_BREAKPOINT));
RegisterDefinition *reg_def = NULL;
ret = 0;
if (check_ip) {
*step_over_hw_bp = 0;
reg_def = get_PC_definition(ctx);
ret = context_read_reg(ctx, reg_def, 0, reg_def->size, &ip);
if ( ret < 0 )
return -1;
}
return 0;
}
This question "Visual Studio 2010's strange "warning LNK4042"" had the solution to my problem.
After all it was a linker problem caused by the compiler..
Under Configuratoin Properties >> C/C++ >> Output Files >> Object File Name I used for both configurations $(IntDir) whereas it worked for Debug but not for Release. Does anybody know why?
Changing it to
$(IntDir)\%(RelativeDir)
was the solution that saved my day.

Resources