建立库时的和未定义符号 [英] Clang and undefined symbols when building a library

查看:167
本文介绍了建立库时的和未定义符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C ++框架,当我使用Clang在OSX上编译它时会遇到一些问题。

I'm working on a C++ framework, and there's a few issues when I compile it on OSX with Clang.

首先,我正在使用其他库,例如openssl和clang抱怨在构建库时某些符号没有解决。它们不应该是:这些库将与最终的二进制文件链接,不应在中介程序上发生。

First of, I'm using some other libraries, such as openssl, and clang complains that some symbols aren't solved when I build the library. They shouldn't be: these libraries will be linked with the final binary, it shouldn't happen on an intermediary.

然后,还有一些方法和变量应该使用GCC在客户端二进制文件中实现,没问题,但是Clang也抱怨这些符号在编译期间无法解决。

Then, there's also a few methods and variables that are supposed to be implemented in the "client" binary... with GCC, no problems, but Clang also complains that these symbols can't be solved during compilation.

怎么会 ?我该怎么办?

How come ? What should I do ?

这是我的CMakeLists.txt,以防可能有用:

Here's my CMakeLists.txt in case that can be useful:

cmake_minimum_required(VERSION 2.8)

project(crails_project)

set(CMAKE_CXX_FLAGS "-std=c++0x -Wall -Wno-deprecated-declarations -pedantic -DASYNC_SERVER -DSERVER_DEBUG -DUSE_MONGODB_SESSION_STORE")

find_package(cppnetlib REQUIRED)

include_directories(include /usr/local/include ${CPPNETLIB_INCLUDE_DIRS} .)

file(GLOB crails_core
     src/*.cpp)

file(GLOB crails_sql
     src/sql/*.cpp)

file(GLOB crails_mongodb
     src/mongodb/*.cpp)

add_library(crails-core    SHARED ${crails_core})
add_library(crails-sql     SHARED ${crails_sql})
add_library(crails-mongodb SHARED ${crails_mongodb})

这是崩溃的命令:

/usr/bin/c++  -std=c++0x -Wall -Wno-deprecated-declarations -pedantic -DASYNC_SERVER -DSERVER_DEBUG -DUSE_MONGODB_SESSION_STORE -dynamiclib -Wl,-headerpad_max_install_names   -o libcrails-core.dylib -install_name /Users/michael/Personal/crails/build/libcrails-core.dylib CMakeFiles/crails-core.dir/src/assets.cpp.o CMakeFiles/crails-core.dir/src/cgi2params.cpp.o CMakeFiles/crails-core.dir/src/cipher.cpp.o [...]

这是我得到的两种错误:

And here are the two kinds of error I get:

架构x86_64的未定义符号:

Undefined symbols for architecture x86_64:

  "_BIO_ctrl", referenced from:
      Cipher::encode_base64(unsigned char*, unsigned int) const in cipher.cpp.o

第二个:

  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for boost::detail::thread_data_base", referenced from:
      boost::detail::thread_data_base::thread_data_base() in server.cpp.o


推荐答案

解决了! Clang需要接收选项 -undefined dynamic_lookup 来编译库时忽略缺少的符号。

Solved it ! Clang needs to receive the option -undefined dynamic_lookup to ignore missing symbols when compiling a library.

将此添加到CMakeFile.txt产生预期的效果:

Add this to the CMakeFile.txt to produce the expected effect:

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS} -undefined dynamic_lookup")
endif()

这篇关于建立库时的和未定义符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆