我无法将静态库链接到Mac OS X上的可执行文件。
我的回购目录lib
包含所有库,例如libstdc++.a
,libssl.a
,libz.a
。
CMakeList.txt包含:
(...)
set(PROJECT_LINK_LIBS libcurl.a libz.a libssl.a libcrypto.a libstdc++.a libjson-c.a)
link_directories(lib/)
add_executable(myapp ${SOURCES})
target_link_libraries(myapp ${PROJECT_LINK_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
编译时我收到了一条消息(对于每个.a
文件):
ld: warning: ignoring file /Users/kuba/CLionProjects/RigService/lib/macos/libz.a, file was built for archive which is not the architecture being linked (x86_64)
和
Undefined symbols for architecture x86_64:
"_curl_easy_cleanup", referenced from:
HTTPConnection::request(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, char const*) in HTTPConnection.cpp.o
"_curl_easy_init", referenced from:
HTTPConnection::request(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, char const*) in HTTPConnection.cpp.o
"_curl_easy_perform", referenced from:
HTTPConnection::request(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, char const*) in HTTPConnection.cpp.o
(...)
我之前在linux上编译了这个,在那里我没有任何问题
我想从.o
中提取所有.a
个文件,并再次使用
ar rcs libcurl.a *.o
但在此之后我遇到了同样的问题 我还试图通过
建立档案libtool -static -o libcurl.a *.o
然后我收到了一条消息:
sal:libcrypto kuba$ libtool -static -o libcrypto.a *.o
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: a_bitstr.o is not an object file (not allowed in a library)
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: a_bool.o is not an object file (not allowed in a library)
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: a_bytes.o is not an object file (not allowed in a library)
(...) // error for each .o file
这是我的问题,也许我应该从中开始,我可以在linux和mac os上编译时链接相同的.a
文件吗?
答案 0 :(得分:2)
您是否尝试使用为Linux构建的库?这不会起作用,你需要为macOS构建的库。