Shark-ML / Shark

The Shark Machine Leaning Library. See more:
http://shark-ml.github.io/Shark/
GNU Lesser General Public License v3.0
493 stars 130 forks source link

Linker error but only when using plain makefile instead of cmake #281

Closed Mad5ci closed 3 years ago

Mad5ci commented 3 years ago

I'm trying to simplify the build process by sidestepping cmake for applications. I successfully built shark and installed it. I am able to build my application if I use cmake; but I want to do it directly with a simple makefile. I get the following link error:

undefined reference to `shark::csvStringToData(shark::Data<remora::vector<double, remora::cpu_tag> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char, char, unsigned long)'

What is cmake doing that my simple makefile is not??


This (with cmake) works:

madscientist@dc3ml2:~/Projects/ARML/restml/cpp-predictor$ cat CMakeLists.txt 
cmake_minimum_required(VERSION 2.8)

# This project is designed to be built outside the Shark source tree.
# set Shark_DIR to the proper location
project(predictor)

# Find the Shark libraries and includes
find_package(Shark REQUIRED)
include(${SHARK_USE_FILE})

# Executable
add_executable(predictor predictor.cpp mlmodel.cpp)
target_link_libraries(predictor ${SHARK_LIBRARIES})

This with a simple makefile does not:

madscientist@dc3ml2:~/Projects/ARML/restml/cpp-predictor$ cat __makefile
CXX = g++
CXXFLAGS = -O3

target: predictor.o mlmodel.o
    $(CXX) $(CXXFLAGS) -o predictor predictor.o mlmodel.o -L/usr/local/lib/libshark.a -lboost_serialization

predictor.o: predictor.cpp mlmodel.hpp
    $(CXX) $(CXXFLAGS) -c predictor.cpp

mlmodel.o: mlmodel.cpp
    $(CXX) $(CXXFLAGS) -c mlmodel.cpp

clean:
    rm -f *.o

What is cmake doing that my makefile is not doing?

I get this result with my makefile:

madscientist@dc3ml2:~/Projects/ARML/restml/cpp-predictor$ make
g++ -O3 -c predictor.cpp
g++ -O3 -c mlmodel.cpp
g++ -O3 -o predictor predictor.o mlmodel.o -L/usr/local/lib/libshark.a -lboost_serialization
mlmodel.o: In function `LongRunningPredictor::mlmodel::predictFromData(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
mlmodel.cpp:(.text+0x342): undefined reference to `shark::csvStringToData(shark::Data<remora::vector<double, remora::cpu_tag> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char, char, unsigned long)'
collect2: error: ld returned 1 exit status
makefile:5: recipe for target 'target' failed
make: *** [target] Error 1

Thanks! _M

Mad5ci commented 3 years ago

I found the solution... minor tweak/misunderstanding in my link recipe. I had to dig through all of the cmake automgical stuff to figure out what it was doing differently (HATE that cmake is so opaque!) The following works:

target: predictor.o mlmodel.o
    $(CXX) $(CXXFLAGS) -o predictor predictor.o mlmodel.o /usr/local/lib/libshark.a -L/usr/local/lib/ -lboost_serialization