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.
Related
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?
Part of my school project I need to work with LabWindows/CVI.
I need to read a xlsx file and analize it.
I download this libxl library.
I amported the h files and the lib files.
this is my code ( I coppied it from here):
#include <cvirte.h>
#include <userint.h>
#include <formatio.h>
#include "Final work.h"
#include "libxl.h"
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static int panelHandle;
int readFile()
{
BookHandle book = xlCreateBook(); // xlCreateXMLBook()
if (xlBookLoad(book, "G:/Electro data/0.5_time_all.xlsx")){
return 0;
}
if(book)
{
SheetHandle sheet = xlBookAddSheet(book, L"Sheet1", 0);
if(sheet)
{
xlSheetWriteStr(sheet, 2, 1, L"Hello, World !", NULL);
xlSheetWriteNum(sheet, 3, 1, 1000, NULL);
}
xlBookSave(book, L"example.xls");
xlBookRelease(book);
}
return 0;
}
and I am getting this errors:
Build Status (Final work.prj - Debug)
Final work.c - 3 warnings
error: Undefined symbol '_xlBookAddSheetA' referenced in "c:\Users\USER\Documents\National Instruments\CVI\cvibuild.Final work\Debug\Final work.obj".
error: Undefined symbol '_xlBookLoadA' referenced in "c:\Users\USER\Documents\National Instruments\CVI\cvibuild.Final work\Debug\Final work.obj".
error: Undefined symbol '_xlBookReleaseA' referenced in "c:\Users\USER\Documents\National Instruments\CVI\cvibuild.Final work\Debug\Final work.obj".
error: Undefined symbol '_xlBookSaveA' referenced in "c:\Users\USER\Documents\National Instruments\CVI\cvibuild.Final work\Debug\Final work.obj".
error: Undefined symbol '_xlCreateBookCA' referenced in "c:\Users\USER\Documents\National Instruments\CVI\cvibuild.Final work\Debug\Final work.obj".
error: Undefined symbol '_xlSheetWriteNumA' referenced in "c:\Users\USER\Documents\National Instruments\CVI\cvibuild.Final work\Debug\Final work.obj".
error: Undefined symbol '_xlSheetWriteStrA' referenced in "c:\Users\USER\Documents\National Instruments\CVI\cvibuild.Final work\Debug\Final work.obj".
Build failed.
here is an image to illustrate:
What am I doing wrong?
You need to link with the provided library. From the screenshot you seem to have added the library to your project, however the linker does not get it.
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);
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.
I know this is some kind of linking error, and is likely due to me missing some kind of compiler option. So please let me know what it is I'm doing wrong.
My code comes from the sample program # http://www.sqlite.org/quickstart.html
#include <stdio.h>
#include <sqlite3.h>
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
int main(int argc, char **argv){
sqlite3 *db;
char *zErrMsg = 0;
int rc;
if( argc!=3 ){
fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
return(1);
}
rc = sqlite3_open(argv[1], &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return(1);
}
rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
sqlite3_close(db);
return 0;
}
I am using the "Developer Command Prompt" in Windows with the following command to compile: (the SQLite header file is in %USERPROFILE%\lib)
cl /I%USERPROFILE%\lib helloworld.c
and I get the following error message:
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23918 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
helloworld.c
Microsoft (R) Incremental Linker Version 14.00.23918.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:helloworld.exe
helloworld.obj
helloworld.obj : error LNK2019: unresolved external symbol _sqlite3_close referenced in function _main
helloworld.obj : error LNK2019: unresolved external symbol _sqlite3_exec referenced in function _main
helloworld.obj : error LNK2019: unresolved external symbol _sqlite3_free referenced in function _main
helloworld.obj : error LNK2019: unresolved external symbol _sqlite3_open referenced in function _main
helloworld.obj : error LNK2019: unresolved external symbol _sqlite3_errmsg referenced in function _main
helloworld.exe : fatal error LNK1120: 5 unresolved externals
Add the sqlite library file on the command line, like this:
cl /I%USERPROFILE%\lib helloworld.c sqlite3.lib
EDIT: It appears they provide a .def file in their precompiled binaries, and no .lib. To create the .lib:
lib /def:sqlite3.def /OUT:sqlite3.lib