How to link a static library in Visual C ++ 2008?

My VC ++ solution has two projects: an application (exe) and a static library.

Both compile fine, but are not related. I get an "unresolved external character" error for every function from the static library that I use. They look like this:

MyApplication.obj: error LNK2019: unresolved external character "__declspec (dllimport) int __cdecl MyStaticLibrary :: accept (int, struct sockaddr *, int *)"

The application finds .lib just fine, so this is not a problem. I think the "dllimport" problem is the problem, why will it be there when I try to create a static library? Both the application and the library use the multi-threaded (/ MT) runtime library rather than the multi-threaded DLL (/ MD).

EDIT:

I think some answers are correct. A library called UDT has this in the main header file:

#ifdef UDT_EXPORTS
   #define UDT_API __declspec(dllexport)
#else
   #define UDT_API __declspec(dllimport)
#endif

Does this mean that it is not intended to be used as a static library?

+1
source share
3 answers

How do you set up a connection? And what does your header file look like for MyApplication and MyStaticLibrary :: accept?

, - Solution- > Properties, . Visual Studio , , ​​ .

, / DLL .

: , . , , ? ( ).

.

1) UDT_API .

2) :

#define UDT_API

3) , :

#ifdef  UDT_STATIC
    #define UDT_API
#else
    #ifdef UDT_EXPORTS
       #define UDT_API __declspec(dllexport)
    #else
       #define UDT_API __declspec(dllimport)
    #endif
#endif

UDT_STATIC , , , . ( .)

+3

, WS2_32.lib .

0

, . ?

, UDT_API . , .lib .

An alternative is to modify lib to create a dll. This way you create a static link to the dll. The only problem is that you have to provide a DLL for your application. Still not a bad decision, as it allows you to make corrections in lib.

0
source

Source: https://habr.com/ru/post/1710466/


All Articles