1

I've been trying to download and build the Stanford Library source files and build a library out of them to use for my own project using the CLion (IDE). I've been following instructions from this answer and my CMakeLists file looks like this:

cmake_minimum_required(VERSION 3.3)
project(Stanford)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_BUILD_TYPE Release)


file(GLOB MyHeaders "*.h" /stacktrace/"*.h" private/"*.h")
file(GLOB MySources "*.cpp" /stacktrace/"*.cpp" private/"*.cpp")
include_directories(MyHeaders)
add_library(Stanford SHARED ${MySources} ${MyHeaders})


target_include_directories (Stanford PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

When opening the run menu, I get the following:Screenshot 1

If I tell it to build anyway I get the following errors.

enter image description here

I've been struggling to find out what why I need an executable to build a library and what those undefined references mean.

Community
  • 1
  • 1
Gabriel Asman
  • 181
  • 1
  • 13
  • `Executable` is needed only if you want to run your program in IDE(CLion). As your project contains only library, you doesn't need to specify anything in `Executable` field. As usual, undefined references means that none of your sources which built into library contains definition of these function. (Instead of `/stacktrace/` in `file(GLOB)` should be `stacktrace/`). – Tsyvarev Jan 23 '16 at 18:30
  • Oh, you're right about the executable, what's still unclear to me is why I get the undefined references, in fact the IDE(auto-complete) sees those references... – Gabriel Asman Jan 23 '16 at 19:46
  • Determine source file, which defines missed functions, and check, that this file is listed in variable `MySources`. You can output value of the variable using `message()` command. – Tsyvarev Jan 23 '16 at 19:48

2 Answers2

1

I don't know if it's the cause of your problem, but include command should look like this: include_directories(${MyHeaders}). ${MyHeaders} will expand the variable MyHeaders and pass its current value to include_directories. Otherwise you are, literally, including directory MyHeaders.

dragn
  • 1,030
  • 1
  • 8
  • 21
0

Standford library provide call_stack_windows.cpp and call_stack_gcc.cpp. Only one should be included. In your case, you should use call_stack_gcc.cpp. call_stack_windows.cpp cannot link with gcc.

So, my answer is: don't use globbing to declare your sources. It is very error prone. If you are lazy, just copy-paste output of find . -name '*.cpp' -o -name '*.h' to your CMakeList.txt.

In add, there are many bad practices in CMakeList.txt you show. I suggest you to read this answer.

Jérôme Pouiller
  • 9,249
  • 5
  • 39
  • 47