3
votes

I am trying to create a shared library using the files present in SOURCE. So I added as suggested by this post.

cmake_minimum_required(VERSION 3.0.2)
project(myproj)

set (SOURCE
    ${SOURCE}
    ${CMAKE_CURRENT_SOURCE_DIR}/src/io/IO1.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/src/io/IO2.cpp
)

add_library(myprojlib SHARED SOURCE)

I get error even though I have set the source :

CMake Error at CMakeLists.txt:34 (add_library): Cannot find source file:

SOURCE

Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx

1
add_library(myprojlib SHARED SOURCE) should be add_library(myprojlib SHARED ${SOURCE}) it thinks you mean SOURCE is the filename of your source cdoe not a variable.drescherjm
Yup! that solved the problem. Thank you :)mato
@mato remember to mark drescherjm's answer as correct :)Rhathin
Yes, will do :)mato
Typos are closed as typos.Matthieu Brucher

1 Answers

4
votes

add_library(myprojlib SHARED SOURCE) should be add_library(myprojlib SHARED ${SOURCE}) CMake expects that you mean SOURCE is the filename of your source cdoe not a CMake variable. The ${} syntax makes it clear that SOURCE is a CMake variable.