提问人:Jomme 提问时间:3/21/2023 最后编辑:Jomme 更新时间:3/21/2023 访问量:359
G++/LD(链接)未定义符号
g++/ld (linking) undefined symbol
问:
尝试将带有静态和动态库的目标文件链接到exe。 哪里出了问题? 没有 -ldsound 的结果相同(dsound.lib;与项目文件位于同一目录中,如 new.o)
$ g++ -static d:/lib/libstk.a new.o -ldsound -o new.exe
ld.lld: error: undefined symbol: __declspec(dllimport) select
>>> referenced by libstk.a(Messager.cpp.obj):(socketHandler)
ld.lld: error: undefined symbol: __WSAFDIsSet
>>> referenced by libstk.a(Messager.cpp.obj):(socketHandler)
>>> referenced by libstk.a(Messager.cpp.obj):(socketHandler)
ld.lld: error: undefined symbol: __declspec(dllimport) WSAGetLastError
>>> referenced by libstk.a(Messager.cpp.obj):(socketHandler)
ld.lld: error: undefined symbol: __declspec(dllimport) CoInitialize
>>> referenced by libstk.a(RtAudio.cpp.obj):(RtAudio::openRtApi(RtAudio::Api))
>>> referenced by libstk.a(RtAudio.cpp.obj):(RtApiDs::RtApiDs())
ld.lld: error: undefined symbol: __declspec(dllimport) CoUninitialize
>>> referenced by libstk.a(RtAudio.cpp.obj):(RtApiDs::~RtApiDs())
.............and so on ..................
我发现运行包含以下内容的配置脚本后生成的 Cmake 文件:
# Create imported target stk
add_library(stk STATIC IMPORTED)
set_target_properties(stk PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "Threads::Threads;winmm;ole32;wsock32;dsound"
)
也许我必须使用这个文件(stk-config.cmake)来代替带有参数的命令行 g++。但是不知道该怎么做。(没有制作文件的经验)
答: 暂无答案
评论