I'm building a dynamic library c
which is linked to a static library b
.
The static library b
is statically linked to the static library a
.
The cmake for c
, roughly looks like this (the cmakes for a
and b
are quite similar):
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
:
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?
Related questions:
Something tells me that your linker output is not quite right. It looks like perhaps a
and b
are trying to be exported classes.
That aside, this line tells us that b
cannot actually see some symbol (perhaps the class default constructor) for library (class) 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
. If you mean what you said in your question, you linker shows the logic error.
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.