I am trying to write a CMakeList.txt in Clion under ubuntu 14.04 as follow:
cmake_minimum_required(VERSION 2.8.3)
project(ify)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++11")
## System dependencies are found with CMake's conventions
find_package(Boost REQUIRED)
include_directories(
${catkin_INCLUDE_DIRS}
/usr/local/include
/usr/include
include
)
include_directories(
include/
)
link_directories(
/usr/local/lib
/usr/lib
libs/x64
/usr/lib/x86_64-linux-gnu
)
#set(SOURCE_FILES main.cpp)
#add_executable(ify ${SOURCE_FILES})
add_executable(ify main.cpp)
target_link_libraries(ify ${catkin_LIBRARIES}
libmsc.so
libasound.so
)
when I run it tells me:
/home/think/ClionProjects/ify/libs/x64/libmsc.so: undefined reference to `dlopen'
/home/think/ClionProjects/ify/libs/x64/libmsc.so: undefined reference to `dlclose'
/home/think/ClionProjects/ify/libs/x64/libmsc.so: undefined reference to `dlerror'
/home/think/ClionProjects/ify/libs/x64/libmsc.so: undefined reference to `dlsym'
/home/think/ClionProjects/ify/libs/x64/libmsc.so: undefined reference to `pthread_create'
After I searched this I tried some methods:
1:add ldl like this:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -ldl -std=c++11")
2:add a target_link_libraries:
target_link_libraries(ify
dl
pthread
)
3:
set(CMAKE_SHARED_LINKER_FLAGS -ldl)
4:add #include <dlfcn.h>
in main.cpp
but neither of these methods works.
Then I tried to compile it without clion and wrote a MakeFile in the folder like this:
DIR_INC = ./include
DIR_BIN = ./bin
DIR_LIB = ./libs
TARGET = demo
BIN_TARGET = $(DIR_BIN)/$(TARGET)
CROSS_COMPILE =
CFLAGS = -g -Wall -I$(DIR_INC)
#
ifdef LINUX64
LDFLAGS := -L$(DIR_LIB)/x64
else
LDFLAGS := -L$(DIR_LIB)/x86
endif
LDFLAGS += -lmsc -lrt -ldl -lpthread
OBJECTS := $(patsubst %.c,%.o,$(wildcard *.c))
$(BIN_TARGET) : $(OBJECTS)
$(CROSS_COMPILE)gcc $(CFLAGS) $^ -o $@ $(LDFLAGS)
%.o : %.c
$(CROSS_COMPILE)gcc -c $(CFLAGS) $< -o $@
clean:
@rm -f *.o $(BIN_TARGET)
.PHONY:clean
This Makefile works, I think it was because this sentence:LDFLAGS += -lmsc -lrt -ldl -lpthread
, but how can I change my My CMakefile.txt in clion, I want it to work in clion.
anyone can help me? thanks a lot.