I have a list of object files generated by a Makefile stored under say mylib
directory. I am trying to link these object files while compiling one of the sub-directories in my project (I don't want to generate an executable). Here is my CMakeLists.txt
file
cmake_minimum_required(VERSION 3.5.1)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED on)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g")
set( CMAKE_EXPORT_COMPILE_COMMANDS ON )
file(GLOB SOURCES "*.cpp" ".hpp")
include_directories(mylib)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/mylib)
add_library(slib SHARED ${SOURCES})
That is, mylib
directory contains .h
, .cc
and .o
files I generated after running make
on mylib
.
When I try to compile this, I get an Undefined symbols for architecture x86_64
error for mylib
functions.
How can I link multiple precompiled object files generated by an external make
? This question (how to add prebuilt object files to executable in cmake) gives a method to link a single object file. How do I do this for all the object files and generated a shared library instead of an executable?