0

I'm trying to build my application. It's organized as following:

-ClipsCore
  |-agenda.c
  |-agenda.h
  |-envrnmnt.c
  |-engrnmnt.h
  |-clips.h  
  |-....
-src
  |-clipsDemo.cpp
-build
-CMakeLists.txt

Here is my CMakeLists.txt

cmake_minimum_required (VERSION 2.8)
project (clipsDemo)
set(MY_CPP_FILES  src/clipsDemo.cpp)
file(GLOB CLIPS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/ClipsCore/*.c)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ClipsCore)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/ClipsCore)
add_library(clipslib ${CLIPS_SRC})
add_executable(${PROJECT_NAME} ${MY_CPP_FILES})
target_link_libraries(${PROJECT_NAME} clipslib)

When I build, I got errors like the following:

undefined reference to `CreateEnvironment()'

Although this function found in envrnmnt.c file which should be linked to the executable as far as I understand. I tried to build the ClipsCore library using add_library then tried to link it to the executable using target_link_libraries. What is wrong with my CMakeLists.txt?

Salahuddin
  • 1,617
  • 3
  • 23
  • 37
  • 1
    it looks ok on the face of it, except you don't need the `link_directories()` line - cmake knows where to find the library target. did you `extern "C"` the definitions of c functions? – Richard Hodges May 24 '17 at 16:41
  • Thanks @RichardHodges. `extern "C"` was missing. Now everything is working fine. Could you add this as an answer? – Salahuddin May 24 '17 at 18:20

0 Answers0