我在Qt Creator中有一个简单的项目(基于Qt 5.8),使用RTI DDS库。我的项目在Qt中通过qmake作为工具构建成功构建并链接。
现在我想用cmake构建工具构建我的项目。所以我写下面的CmakeLists.txt。但我得到RTI库的链接错误。我带来了qmake和cmake文件。请告诉我我做错了什么;
qmake(.pro文件):
QT += core
QT -= gui
DEFINES += "_GLIBCXX_USE_CXX11_ABI=0"
QMAKE_CXXFLAGS+=-std=c++11
TARGET = untitled
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
datawriter.cpp \
../../../Repositories/tests/r.karimi/Publisher/data/IDLs/myIDL/myIDL.cxx \
../../../Repositories/tests/r.karimi/Publisher/data/IDLs/myIDL/myIDLImpl.cxx \
../../../Repositories/tests/r.karimi/Publisher/data/IDLs/myIDL/myIDLImplPlugin.cxx
HEADERS += \
datawriter.h \
../../../Repositories/tests/r.karimi/Publisher/data/IDLs/myIDL/myIDL.hpp \
../../../Repositories/tests/r.karimi/Publisher/data/IDLs/myIDL/myIDLImpl.h \
../../../Repositories/tests/r.karimi/Publisher/data/IDLs/myIDL/myIDLImplPlugin.h
QMAKE_CXXFLAGS += -DRTI_UNIX
QMAKE_CXXFLAGS += -DRTI_LINUX
QMAKE_CXXFLAGS += -DRTI_64BIT
unix:LIBS += -L$$(NDDSHOME)/lib/x64Linux3gcc4.8.2 -lnddscd -lnddscored -lnddscpp2d -lrtidlcppd -lrtirsinfrastructured
INCLUDEPATH += .. \
$$(NDDSHOME)/include/ndds/hpp \
$$(NDDSHOME)/include \
$$(NDDSHOME)/include/ndds \
$$(NDDSHOME)/include/persistence \
../../../Repositories/tests/r.karimi/Publisher/data/IDLs/myIDL \
的CMakeLists.txt
cmake_minimum_required(VERSION 3.7)
project(Publisher)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
# Add RTI flags:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DRTI_UNIX")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DRTI_LINUX")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DRTI_64BIT")
macro(add_idl_files LIBNAME)
include_directories($ENV{HOME}/tests/r.karimi/Publisher/data/IDLs/${LIBNAME})
list(APPEND SOURCE_FILES $ENV{HOME}/tests/r.karimi/Publisher/data/IDLs/${LIBNAME}/${LIBNAME}.cxx)
list(APPEND SOURCE_FILES $ENV{HOME}/tests/r.karimi/Publisher/data/IDLs/${LIBNAME}/${LIBNAME}Impl.cxx)
list(APPEND SOURCE_FILES $ENV{HOME}/tests/r.karimi/Publisher/data/IDLs/${LIBNAME}/${LIBNAME}ImplPlugin.cxx)
list(APPEND HEADER_FILES $ENV{HOME}/tests/r.karimi/Publisher/data/IDLs/${LIBNAME}/${LIBNAME}.hpp)
list(APPEND HEADER_FILES $ENV{HOME}/tests/r.karimi/Publisher/data/IDLs/${LIBNAME}/${LIBNAME}Impl.h)
list(APPEND HEADER_FILES $ENV{HOME}/tests/r.karimi/Publisher/data/IDLs/${LIBNAME}/${LIBNAME}ImplPlugin.h)
endmacro()
set(SOURCE_FILES src/main.cpp src/DataWriter.cpp)
set(HEADER_FILES include/DataWriter.h)
include_directories(
include
# RTI
$ENV{NDDSHOME}/include
$ENV{NDDSHOME}/include/ndds
$ENV{NDDSHOME}/include/ndds/hpp
$ENV{NDDSHOME}/include/persistence
)
# Add DDS Libs
add_idl_files(myIDL)
set(
LIBS
#RTI
nddscd
nddscored
nddscpp2d
rtidlcppd
rtirsinfrastructured
)
link_directories(
$ENV{NDDSHOME}/lib/x64Linux3gcc4.8.2
)
set(CMAKE_VERBOSE_MAKEFILE ON)
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES})
target_link_libraries(${PROJECT_NAME} ${LIBS})
链接错误:
.../libnddscored.so: undefined reference to `dlopen'
.../libnddscored.so: undefined reference to `dlclose'
.../libnddscored.so: undefined reference to `dlerror'
.../libnddscored.so: undefined reference to `dlsym'
提前感谢您的帮助。 礼
答案 0 :(得分:2)
.../libnddscored.so: undefined reference to `dlopen'
.../libnddscored.so: undefined reference to `dlclose'
.../libnddscored.so: undefined reference to `dlerror'
.../libnddscored.so: undefined reference to `dlsym'
这些符号在-ldl
中定义。只需将${CMAKE_DL_LIBS}
添加到target_link_libraries()
。