09-28-2017 12:15 PM
I have built an import library (.lib) using VS 2010 and I have added the library file to my LabWindows application (LabWindows 2012)
This is the prototype of the function in the .lib library:
extern void test();
When I call the "test" function in my LabWindows application, I get a link error:
"Undefined symbol '-test' reference in "Main.c"
When I dump the .lib library, I can find the symbol _test in the library:
197 00000000 SECT5C notype () External | _test
I have gone through many discussion threads and NI pages and I can't figure out why I get the link error. Any help is much appreciated.
09-29-2017 04:43 PM
Hi ah,
Can you post a small reproducing case of the code on this forum? Thanks.
09-29-2017 05:14 PM
Sure... You can reproduce the issue with simple project. I have attached a VS2010 project (DdsTest). This project generates a library DdsTest.lib. Unzip the file and open DdsTest.sln solution.
Then create a LabWindows project (2012) and create a source file and header file as following:
main.c - this is the content of the c file
//********************
// Include files
#include <ansi_c.h>
#include <stdio.h>
#include "Test.h"
int main(int argc, char **argv)
{
printf("hello world!\n");
//StartApp(argc, argv);
test();
char c;
scanf("%c", &c);
return 0;
}
//*****************
Test.h - this is the content of the header file:
#ifndef TEST_MAIN_H
#define TEST_MAIN_H
extern "C" {
extern void test();
}
#endif
The definition of the function test() is in DdsTest.lib. You need to add DdsTest.lib file to your LabWindows project.
Then try to compile the labwindows project and you will end up with this link error:
Undefined symbol '_test' referenced in "Main.c".
The VS2010 project has WS2_32.lib as additional library dependency. If you remove this library from the VS2010 project (DdsTest) and rebuild the DdsTest.lib and re-link to your labwindows project, te LabWindows project compiles and runs fine.
Now the question is why adding WS2_32.lib as dependency library would cause the linking fail in the LabWindows project.