4

I am trying to convert a Makefile project to cmake.

My project has an executable which gets built and linked to both an internal shared library, and an external shared library (there are dependencies in the executable to both).

Here is my old Makefile (generalised):

Include = -I$(PROJ_DIRECTORY)/include -I/${EXTERN}/lnInclude
Library = -L$(PROJ_DIRECTORY)/build -lshared  -L$(EXTERN_LIBBIN) -lextern
CPPFLAGS    = -D_GLIBCXX_DEBUG -DProjectRescource=$(PROJ_DIRECTORY)/resources -O0 -g3 -Wall -c -fpermissive -std=c++0x -fPIC -MMD -MP
CCC     = g++
TARGET      = ExecutableName

all: $(TARGET)

clean:
    rm -f $(TARGET).o $(TARGET).d $(TARGET)

$(TARGET) : $(TARGET).o
    $(CCC) -o $(TARGET) $(TARGET).o $(Library) 

$(TARGET).o : 
    $(CCC) $(Include) $(CPPFLAGS) $(TARGET).cpp

Here is my attempt at CMakeLists.txt (generalised):

include_directories(${PROJECT_SOURCE_DIR}/include/)
add_executable(test1 test1.cpp)
set (CMAKE_CXX_FLAGS "-D_GLIBCXX_DEBUG -DProjectRescource=${PROJECT_SOURCE_DIR}/resources -O0 -g3 -Wall -fpermissive -std=c++0x -fPIC -MMD -MP")
include_directories($ENV{EXTERN_INCLUDE}/lnInclude)
target_link_libraries(test1 "$ENV{EXTERN_LIBBIN}/libextern.so" Project)

When I run the executable, calls to functions defined in the include directory return -nan. Does anyone know why?

Thomas5631
  • 244
  • 1
  • 11
  • may be you forget to something like `libextern_init` ? – fghj May 12 '16 at 14:39
  • `When I run the executable, calls to functions defined in the include directory return -nan.` - it is depended from the external library why its functions return "-nan". But we know nothing about that library. – Tsyvarev May 12 '16 at 18:16
  • 1
    Check http://stackoverflow.com/questions/15100351/changing-cmake-cxx-flags-in-project for correct compile options definitions. – user3159253 May 12 '16 at 20:19

1 Answers1

2

The reason for the issue was due to the linking order of the shared libraries.

I was able to solve the problem by changing the last line of CMakeLists.txt to:

target_link_libraries(test1 Project "$ENV{EXTERN_LIBBIN}/libextern.so")
Thomas5631
  • 244
  • 1
  • 11