[英]Linking a static library to a shared library in MSVC causes unresolved symbol
I'm building a dynamic library c
which is linked to a static library b
. 我正在构建一个链接到静态库
b
的动态库c
。
The static library b
is statically linked to the static library a
. 静态库
b
静态链接到静态库a
。
The cmake for c
, roughly looks like this (the cmakes for a
and b
are quite similar): c
的cmake大致如下所示( a
和b
的cmake非常相似):
cmake_minimum_required(VERSION 2.6)
project(c)
include_directories(../b/src)
link_directories(../b/Debug)
add_library(c SHARED src/c.cpp)
target_link_libraries(c PRIVATE b)
The issue I'm facing is related to the fact that c
can't see references to functions defined in a
: 我面临的问题与
c
无法看到对在a
定义的函数的引用有关:
b.lib(b.obj) : error LNK2019: unresolved external symbol "int __cdecl a(void)" (?a@@YAHXZ) referenced in function "int __cdecl b(void)" (?b@@YAHXZ) [C:\Users\user\Workspace\garbage\c\c.vcxproj]
C:\Users\user\Workspace\garbage\c\Debug\c.dll : fatal error LNK1120: 1 unresolved externals [C:\Users\user\Workspace\garbage\c\c.vcxproj]
Is there any way for c
to properly link? c
有什么方法可以正确链接吗?
Related questions: 相关问题:
Linking static libraries to other static libraries 将静态库链接到其他静态库
Something tells me that your linker output is not quite right. 告诉我您的链接器输出不正确。 It looks like perhaps
a
and b
are trying to be exported classes. 似乎
a
和b
试图导出类。
That aside, this line tells us that b
cannot actually see some symbol (perhaps the class default constructor) for library (class) a
: 除此之外,这一行告诉我们
b
实际上看不到库(类) a
某些符号(也许是类的默认构造函数):
b.lib(b.obj) : error LNK2019: unresolved external symbol "int __cdecl a(void)" (?a@@YAHXZ) referenced in function "int __cdecl b(void)" (?b@@YAHXZ)
In fact, your CMake example never links a
to b
and, your original questions says that b
is linked into a
. 实际上,您的CMake示例从不将
a
链接到b
并且您最初的问题是b
链接到a
。 If you mean what you said in your question, you linker shows the logic error. 如果您的意思是您在问题中所说的,则链接程序将显示逻辑错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.