简体   繁体   English

无法在Mac OS X上链接静态库

[英]Can't link static library on Mac OS X

I can't link static libraries to executable file on Mac OS X. I have in my repo directory lib witch contains all of libraries such as libstdc++.a , libssl.a , libz.a . 我不能静态库链接到可执行文件在Mac OS X我在我的回购目录lib女巫包含了所有的库如libstdc++.alibssl.alibz.a

CMakeList.txt contains: 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})

While compiling I got a messages (for each .a file): 编译时,我收到一条消息(对于每个.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)

and: 和:

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
(...)

I have compilate this on a linux before, and there I didn't have any problem. 我以前在Linux上编译过此文件,现在没有任何问题。
I was tring to extract all .o files from .a and again build a archive file using 我正试图从.a提取所有.o文件,然后再次使用构建文件

ar rcs libcurl.a *.o

but after it I got the same problem. 但是之后我遇到了同样的问题。
I was also trying to build a archive via 我也在尝试通过

libtool -static -o libcurl.a *.o

but then I got a message: 但后来我收到一条消息:

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

And here is my question, maybe should I start from it, can I link the same .a files while compilating on linux and mac os? 这是我的问题,也许我应该从它开始, 在Linux和Mac OS上编译时可以链接相同的.a文件吗?

Are you trying to use libraries built for Linux? 您是否要使用为Linux构建的库? That won't work, you need libraries built for macOS. 那行不通,您需要为macOS构建的库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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