简体   繁体   中英

Unresolved external symbol, with static lib that uses another static lib

I have a C++ program, ProgramA, which is an executable that has a static library, LibraryB, which in turn relies on another static library (libcurl, actually) that is not compiled within my project.

Now, on OSX this works fine. I make sure to link libcurl and ProgramA and LibraryB compile and ProgramA runs great.

However, on Windows, I keep getting linking errors:

error LNK2019: unresolved external symbol __imp_curl_global_init referenced in function

I've double and triple checked that I'm linking the libcurl static library into the project. And actually, in the Visual Studio solution, I have another executable, ProgramB, which doesn't use LibraryB but instead references the libcurl library directly, and this works fine. Unless I include LibraryB in which case the unresolved errors come back.

Suggestions? Thoughts? Thank you!

The problem is that you are linking against the static version of the library but building against the shared version (DLL) of the library. When building against the shared version symbols are exported using __declspec(export) (or a .def file) which causes the compiler to add __imp to the beginning of the exported symbol name.

Te resolve this you can add CURL_STATICLIB to the preprocessor definitions of the dependent project to build against the static library correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM