Static library issue

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello
I have created what you would think would be the simplest of static
libraries, and still I cannot get it to link correctly.
In the static library (main.c) I have:

long __cdecl getnum(long testinput)
{

return 42;
}

and in the console app I have to test it, I have:

extern long __cdecl getnum(long testinput);
long _tmain(long argc, _TCHAR* argv[])
{
printf("number is %d", getnum(7));

}

I have the output .lib file of the first project added to the additional
linker dependencies in project properties, and the static library project's
output folder in the additional include directories for the test project.
Yet I get the error

libtest.obj : error LNK2019: unresolved external symbol "long __cdecl
getnum(long)" (?getnum@@YAJJ@Z) referenced in function _main
Debug/libtest.exe : fatal error LNK1120: 1 unresolved externals
 
Bonj said:
Hello
I have created what you would think would be the simplest of static
libraries, and still I cannot get it to link correctly.
In the static library (main.c) I have:

long __cdecl getnum(long testinput)
{

return 42;
}

and in the console app I have to test it, I have:

extern long __cdecl getnum(long testinput);
long _tmain(long argc, _TCHAR* argv[])
{
printf("number is %d", getnum(7));

}

I have the output .lib file of the first project added to the additional
linker dependencies in project properties, and the static library project's
output folder in the additional include directories for the test project.
Yet I get the error

libtest.obj : error LNK2019: unresolved external symbol "long __cdecl
getnum(long)" (?getnum@@YAJJ@Z) referenced in function _main
Debug/libtest.exe : fatal error LNK1120: 1 unresolved externals

It looks like you have compiled your library module as a C program and
your main module as a C++ program. The compiler does different name
"decoration" for these so the linker is seeing two different names.

In your main program the function name getnum has been decorated as
?getnum@@YAJJ@Z and in the library it's probably _getnum.

You can fix this by changing getnum.c to getnum.cpp so that it compiles
as C++.

Norm
 
Back
Top