"undefined reference to" in MakeFile - c++

I'm a noob to MakeFile. I have read all similar posts on stackoverflow. But still don't know how to do (I'm sure this is a MakeFile problem because I can run it with XCode). Here are my MakeFile and Error msg:
####### Detect system architecture
SYSARCH = i386
ifeq ($(shell uname -m),x86_64)
SYSARCH = x86_64
endif
####### Compiler, tools and options
CXX = g++
LINK = g++
MAKE = make
DELETEFILE = rm -f
DELETEDIR = rm -Rf
DEFINES = -DQT_WEBKIT -DGL_GLEXT_PROTOTYPES
COMMONFLAGS = -Wall -Wextra -pipe -msse2 -Wno-reorder
#-Werror
####### Detect debug or release
DEBUG ?= 0
CXXFLAGS ?=
ifeq ($(DEBUG), 1)
CXXFLAGS += $(COMMONFLAGS) -DDEBUG -DOVR_BUILD_DEBUG -g $(DEFINES)
RELEASETYPE ?= Debug
LFLAGS =
else
CXXFLAGS += $(COMMONFLAGS) -O2 $(DEFINES)
RELEASETYPE ?= Release
LFLAGS = -O1 # Why O1?
endif
####### Paths
OCULUSWORLDPATH = .
LIBOVRPATH = ../../LibOVR
COMMONSRCPATH = ../CommonSrc
3RDPARTYPATH = ../../3rdParty
INCPATH = -I. -I.. -I$(COMMONSRCPATH) -I$(LIBOVRPATH)/Include -I$(LIBOVRPATH)/Src
OBJPATH = ./Obj/Linux/$(RELEASETYPE)/$(SYSARCH)
CXX_BUILD = $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJPATH)/
####### Files
LIBS = -L$(LIBOVRPATH)/Lib/Linux/$(RELEASETYPE)/$(SYSARCH) \
-lovr \
-ludev \
-lpthread \
-lGL \
-lX11 \
-lXrandr \
-lrt
TARGET = ./Release/OculusWorldDemo_$(SYSARCH)_$(RELEASETYPE)
####### Rules
all: $(TARGET)
OCULUSWORLD_SOURCE = $(OCULUSWORLDPATH)/OculusWorldDemo.cpp \
$(OCULUSWORLDPATH)/OculusWorldDemo_Scene.cpp \
$(OCULUSWORLDPATH)/Player.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Util/RenderProfiler.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Util/OptionMenu.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Platform/Linux_Gamepad.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Platform/Linux_Platform.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Platform/Platform.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Render/Render_Device.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Render/Render_GL_Device.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Render/Render_LoadTextureDDS.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Render/Render_LoadTextureTGA.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Render/Render_XmlSceneLoader.cpp \
$(OCULUSWORLDPATH)/../../3rdParty/TinyXml/tinyxml2.cpp
OCULUSWORLD_OBJECTS = $(patsubst $(OCULUSWORLDPATH)%.cpp,$(OBJPATH)%.o,$(OCULUSWORLD_SOURCE))
OBJECTS = $(OTHER_OBJECTS) $(OCULUSWORLD_OBJECTS)
$(OBJPATH)/%.o: %.cpp
-mkdir -p $(dir $#)
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $# $<
$(LIBOVRPATH)/Lib/Linux/$(RELEASETYPE)/$(SYSARCH)/libovr.a:
$(MAKE) -C $(LIBOVRPATH) DEBUG=$(DEBUG)
lib: $(LIBOVRPATH)/Lib/Linux/$(RELEASETYPE)/$(SYSARCH)/libovr.a
run: $(TARGET)
$(TARGET)
$(TARGET): $(OBJECTS) lib
-mkdir -p $(dir $#)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(LIBS)
clean:
-$(DELETEFILE) $(OBJECTS)
-$(DELETEFILE) $(TARGET)
cleanall:
-$(DELETEFILE) $(OBJECTS)
-$(DELETEDIR) ./Release/*
xxx:~/Desktop/ing$ make
true
make -C ./LibOVR
make[1]: Entering directory `/home/bosch3d/Desktop/ing/LibOVR'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/bosch3d/Desktop/ing/LibOVR'
make -C ./Samples/OculusWorldDemo
make[1]: Entering directory `/home/bosch3d/Desktop/ing/Samples/OculusWorldDemo'
mkdir -p Release/
g++ -O1 -o ./Release/OculusWorldDemo_x86_64_Release ./Obj/Linux/Release/x86_64/OculusWorldDemo.o ./Obj/Linux/Release/x86_64/OculusWorldDemo_Scene.o ./Obj/Linux/Release/x86_64/Player.o ./Obj/Linux/Release/x86_64/../CommonSrc/Util/RenderProfiler.o ./Obj/Linux/Release/x86_64/../CommonSrc/Util/OptionMenu.o ./Obj/Linux/Release/x86_64/../CommonSrc/Platform/Linux_Gamepad.o ./Obj/Linux/Release/x86_64/../CommonSrc/Platform/Linux_Platform.o ./Obj/Linux/Release/x86_64/../CommonSrc/Platform/Platform.o ./Obj/Linux/Release/x86_64/../CommonSrc/Render/Render_Device.o ./Obj/Linux/Release/x86_64/../CommonSrc/Render/Render_GL_Device.o ./Obj/Linux/Release/x86_64/../CommonSrc/Render/Render_LoadTextureDDS.o ./Obj/Linux/Release/x86_64/../CommonSrc/Render/Render_LoadTextureTGA.o ./Obj/Linux/Release/x86_64/../CommonSrc/Render/Render_XmlSceneLoader.o ./Obj/Linux/Release/x86_64/../../3rdParty/TinyXml/tinyxml2.o -L../../LibOVR/Lib/Linux/Release/x86_64 -lovr -ludev -lpthread -lGL -lX11 -lXrandr -lrt
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `OculusWorldDemoApp::~OculusWorldDemoApp()':
OculusWorldDemo.cpp:(.text+0x756): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text+0x7d6): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text+0x836): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text+0x843): undefined reference to `cv::Mat::deallocate()'
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `OculusWorldDemoApp::RenderEyeView(ovrEyeType)':
OculusWorldDemo.cpp:(.text+0x9064): undefined reference to `ReadDataRunML::run(bool)'
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `cv::Mat::~Mat()':
OculusWorldDemo.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x89): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x79): undefined reference to `cv::fastFree(void*)'
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `ReadDataRunML::~ReadDataRunML()':
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLD2Ev[_ZN13ReadDataRunMLD5Ev]+0xa6): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLD2Ev[_ZN13ReadDataRunMLD5Ev]+0x120): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLD2Ev[_ZN13ReadDataRunMLD5Ev]+0x144): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLD2Ev[_ZN13ReadDataRunMLD5Ev]+0x154): undefined reference to `cv::Mat::deallocate()'
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `ReadDataRunML::ReadDataRunML(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, double, int, int)':
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x1a3): undefined reference to `cv::String::allocate(unsigned long)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x1eb): undefined reference to `cv::ml::TrainData::loadFromCSV(cv::String const&, int, int, int, cv::String const&, char, char)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x1f8): undefined reference to `cv::String::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x20b): undefined reference to `cv::String::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x2ec): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x3db): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x4c7): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x5bf): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x6b8): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x6c7): undefined reference to `cv::Formatter::get(int)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x7c1): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x861): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x86e): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x882): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x88f): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x929): undefined reference to `cv::String::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x975): undefined reference to `cv::String::deallocate()'
collect2: ld returned 1 exit status
make[1]: *** [Release/OculusWorldDemo_x86_64_Release] Error 1
make[1]: Leaving directory `/home/bosch3d/Desktop/ing/Samples/OculusWorldDemo'
make: *** [Samples/OculusWorldDemo/Release/OculusWorldDemo_x86_64_Release] Error 2
xxx:~/Desktop/ing$
I have added:
-lopencv_core \
-lopencv_highgui \
-lopencv_imgproc \
-lopencv_video \
-lopencv_objdetect \
Now the Errors are:
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `OculusWorldDemoApp::RenderEyeView(ovrEyeType)':
OculusWorldDemo.cpp:(.text+0x9064): undefined reference to `ReadDataRunML::run(bool)'
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `ReadDataRunML::ReadDataRunML(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, double, int, int)':
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x1eb): undefined reference to `cv::ml::TrainData::loadFromCSV(cv::String const&, int, int, int, cv::String const&, char, char)'
collect2: ld returned 1 exit status
make[1]: *** [Release/OculusWorldDemo_x86_64_Release] Error 1
make[1]: Leaving directory `/home/bosch3d/Desktop/ing/Samples/OculusWorldDemo'
make: *** [Samples/OculusWorldDemo/Release/OculusWorldDemo_x86_64_Release] Error 2
ReadDataRunML is a class added by myself. How should I add it to MakeFile?

You need to add the opencv libraries to the list of libs you link with:
Add to the LIBS section of your MakeFile:
-lopencv_core \
and, depending on which opencv features you use, you may need one or more of the following:
-lopencv_highgui \
-lopencv_imgproc \
-lopencv_video \
-lopencv_objdetect \
The unresolved externals are simply because the linker doesn't know where to look for them. Also, make sure your opencv library path is either in your lib path or add it to the libpath used by the linker. You can add to the library path with the -L option, e.g. -LMyLocalPathToOpenCV (rather than hard-coding it where you add it to the linker options, you'll probably want define it and use a macro to refer to it, to keep your makefile cleaner, e.g. $(OPENCV_LIB_PATH)).

Related

My project won't compile with undefined reference error like "undefined reference to `grpc::g_core_codegen_interface'"

I just implemented the distributed version of a database project using gRPC. When I tried to make with my makefile, I keep getting the undefined reference errors with protobuf and gRPC. Parts of the outputs of make is below. I only included a portion of it because of the word limits.
g++ -o rundb benchmarks/ycsb_query.o benchmarks/tpcc_wl.o benchmarks/ycsb_wl.o benchmarks/ycsb_store_procedure.o benchmarks/tpcc_query.o benchmarks/tpcc_helper.o benchmarks/tpcc_store_procedure.o concurrency_control/lock_manager.o concurrency_control/tictoc_manager.o concurrency_control/row_f1.o concurrency_control/row_lock.o concurrency_control/f1_manager.o concurrency_control/row_tictoc.o storage/catalog.o storage/index_hash.o storage/index_btree.o storage/index_base.o storage/row.o storage/log.o storage/table.o system/stats.o system/manager.o system/cc_manager.o system/thread.o system/global.o system/logging_thread.o system/store_procedure.o system/txn.o system/worker_thread.o system/parser.o system/workload.o system/txn_table.o system/main.o system/caching.o utils/helper.o utils/semaphore_sync.o utils/packetize.o grpc/grpc_async_client.o grpc/grpc_sync_server.o grpc/grpc_async_server.o grpc/grpc_sync_client.o -Wall -L./libs -pthread -lrt -std=c++0x -O3 -ljemalloc -lprotobuf -Wall -g -std=c++11 -I. -I./benchmarks -I./concurrency_control -I./storage -I./system -I./transport -I./utils -I./grpc -I./grpc_system -D NOGRAPHITE=1 -O3 -g -ggdb
/usr/bin/ld: concurrency_control/lock_manager.o: in function `google::protobuf::internal::GenericTypeHandler<sundial_rpc::SundialRequest_TupleData>::New(google::protobuf::Arena*)':
/usr/local/include/google/protobuf/repeated_field.h:802: undefined reference to `sundial_rpc::SundialRequest_TupleData* google::protobuf::Arena::CreateMaybeMessage<sundial_rpc::SundialRequest_TupleData>(google::protobuf::Arena*)'
/usr/bin/ld: system/stats.o: in function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const& sundial_rpc::SundialRequest_RequestType_Name<unsigned int>(unsigned int)':
/home/libin/Sundial/./grpc_system/sundial_grpc.pb.h:105: undefined reference to `sundial_rpc::SundialRequest_RequestType_descriptor()'
/usr/bin/ld: system/stats.o: in function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const& sundial_rpc::SundialResponse_ResponseType_Name<unsigned int>(unsigned int)':
/home/libin/Sundial/./grpc_system/sundial_grpc.pb.h:136: undefined reference to `sundial_rpc::SundialResponse_ResponseType_descriptor()'
/usr/bin/ld: system/txn.o: in function `google::protobuf::internal::GenericTypeHandler<sundial_rpc::SundialResponse_TupleData>::New(google::protobuf::Arena*)':
/usr/local/include/google/protobuf/repeated_field.h:802: undefined reference to `sundial_rpc::SundialResponse_TupleData* google::protobuf::Arena::CreateMaybeMessage<sundial_rpc::SundialResponse_TupleData>(google::protobuf::Arena*)'
/usr/bin/ld: system/txn.o: in function `TxnManager::RemoteNodeInfo::~RemoteNodeInfo()':
/home/libin/Sundial/system/txn.h:102: undefined reference to `sundial_rpc::SundialResponse::~SundialResponse()'
/usr/bin/ld: /home/libin/Sundial/system/txn.h:102: undefined reference to `sundial_rpc::SundialRequest::~SundialRequest()'
/usr/bin/ld: system/txn.o: in function `sundial_rpc::SundialRequest::SundialRequest()':
/home/libin/Sundial/./grpc_system/sundial_grpc.pb.h:494: undefined reference to `sundial_rpc::SundialRequest::SundialRequest(google::protobuf::Arena*)'
/usr/bin/ld: system/txn.o: in function `sundial_rpc::SundialResponse::SundialResponse()':
/home/libin/Sundial/./grpc_system/sundial_grpc.pb.h:909: undefined reference to `sundial_rpc::SundialResponse::SundialResponse(google::protobuf::Arena*)'
/usr/bin/ld: system/txn.o: in function `TxnManager::send_remote_read_request(unsigned long, unsigned long, unsigned long, unsigned long, access_t)':
/home/libin/Sundial/system/txn.cpp:301: undefined reference to `sundial_rpc::SundialRequest::Clear()'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:302: undefined reference to `sundial_rpc::SundialResponse::Clear()'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:309: undefined reference to `sundial_rpc::SundialResponse::SundialResponse(sundial_rpc::SundialResponse const&)'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:309: undefined reference to `sundial_rpc::SundialRequest::SundialRequest(sundial_rpc::SundialRequest const&)'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:309: undefined reference to `sundial_rpc::SundialRequest::~SundialRequest()'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:309: undefined reference to `sundial_rpc::SundialResponse::~SundialResponse()'
/usr/bin/ld: system/txn.o: in function `google::protobuf::internal::GenericTypeHandler<sundial_rpc::SundialRequest_ReadRequest>::New(google::protobuf::Arena*)':
/usr/local/include/google/protobuf/repeated_field.h:802: undefined reference to `sundial_rpc::SundialRequest_ReadRequest* google::protobuf::Arena::CreateMaybeMessage<sundial_rpc::SundialRequest_ReadRequest>(google::protobuf::Arena*)'
/usr/bin/ld: system/txn.o: in function `TxnManager::process_2pc_phase1()':
/home/libin/Sundial/system/txn.cpp:351: undefined reference to `sundial_rpc::SundialRequest::Clear()'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:352: undefined reference to `sundial_rpc::SundialResponse::Clear()'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:362: undefined reference to `sundial_rpc::SundialResponse::SundialResponse(sundial_rpc::SundialResponse const&)'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:362: undefined reference to `sundial_rpc::SundialRequest::SundialRequest(sundial_rpc::SundialRequest const&)'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:362: undefined reference to `sundial_rpc::SundialRequest::~SundialRequest()'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:362: undefined reference to `sundial_rpc::SundialResponse::~SundialResponse()'
/usr/bin/ld: system/txn.o: in function `TxnManager::process_2pc_phase2(RC)':
/home/libin/Sundial/system/txn.cpp:420: undefined reference to `sundial_rpc::SundialRequest::Clear()'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:421: undefined reference to `sundial_rpc::SundialResponse::Clear()'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:429: undefined reference to `sundial_rpc::SundialResponse::SundialResponse(sundial_rpc::SundialResponse const&)'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:429: undefined reference to `sundial_rpc::SundialRequest::SundialRequest(sundial_rpc::SundialRequest const&)'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:429: undefined reference to `sundial_rpc::SundialRequest::~SundialRequest()'
/usr/bin/ld: /home/libin/Sundial/grpc/grpc_sync_client.cpp:37: undefined reference to `sundial_rpc::Sundial_GRPC_SYNC::Stub::contactRemote(grpc_impl::ClientContext*, sundial_rpc::SundialRequest const&, sundial_rpc::SundialResponse*)'
/usr/bin/ld: /home/libin/Sundial/grpc/grpc_sync_client.cpp:36: undefined reference to `grpc_impl::ClientContext::~ClientContext()'
/usr/bin/ld: grpc/grpc_sync_client.o: in function `sundial_rpc::Sundial_GRPC_SYNC::Stub::~Stub()':
/home/libin/Sundial/./grpc_system/sundial_grpc.grpc.pb.h:73: undefined reference to `vtable for sundial_rpc::Sundial_GRPC_SYNC::Stub'
/usr/bin/ld: grpc/grpc_sync_client.o: in function `sundial_rpc::Sundial_GRPC_SYNC::Stub::~Stub()':
/home/libin/Sundial/./grpc_system/sundial_grpc.grpc.pb.h:73: undefined reference to `vtable for sundial_rpc::Sundial_GRPC_SYNC::Stub'
/usr/bin/ld: grpc/grpc_sync_client.o: in function `Sundial_Sync_Client::contactRemote(unsigned long, sundial_rpc::SundialRequest, sundial_rpc::SundialResponse)':
/home/libin/Sundial/grpc/grpc_sync_client.cpp:36: undefined reference to `grpc_impl::ClientContext::~ClientContext()'
collect2: error: ld returned 1 exit status
make: *** [Makefile:20: rundb] Error 1
I did read some other previous posts suggesting it is caused by not linking the protobuf library but I did include it in LDFLAGS. The makefile is below.
CC=g++
CFLAGS=-Wall -g -std=c++11
.SUFFIXES: .o .cpp .h
SRC_DIRS = ./ ./benchmarks/ ./concurrency_control/ ./storage/ ./system/ ./transport/ ./utils/ ./grpc/ ./grpc_system/
INCLUDE = -I. -I./benchmarks -I./concurrency_control -I./storage -I./system -I./transport -I./utils -I./grpc -I./grpc_system
CFLAGS += $(INCLUDE) -D NOGRAPHITE=1 -O3 -g -ggdb
LDFLAGS = -Wall -L./libs -pthread -lrt -std=c++0x -O3 -ljemalloc -lprotobuf
LDFLAGS += $(CFLAGS)
CPPS = $(foreach dir, $(SRC_DIRS), $(wildcard $(dir)*.cpp))
OBJS = $(CPPS:.cpp=.o)
DEPS = $(CPPS:.cpp=.d)
all:rundb
rundb : $(OBJS)
$(CC) -o $# $^ $(LDFLAGS)
-include $(OBJS:%.o=%.d)
%.d: %.cpp
$(CC) -MM -MT $*.o -MF $# $(CFLAGS) $<
%.o: %.cpp %.d
$(CC) -c $(CFLAGS) -o $# $<
.PHONY: clean
clean:
rm -f rundb *.o */*.o *.d */*.d
So I thought LDFLAGS = -Wall -L./libs -pthread -lrt -std=c++0x -O3 -ljemalloc -lprotobuf would resolve this but it did not.
You can try following these two steps:
Step 1:
Add the below two lines in your makefile:
CFLAGS += `pkg-config --cflags protobuf grpc`
LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
-lgrpc++_reflection\
-ldl
Please refer this Makefile (C++ grpc example for load balancing): https://chromium.googlesource.com/external/github.com/grpc/grpc/+/HEAD/examples/cpp/load_balancing/Makefile
Your Makefile should look like this:
CC=g++
CFLAGS=-Wall -g -std=c++11
# Add the below line
CFLAGS += `pkg-config --cflags protobuf grpc`
.SUFFIXES: .o .cpp .h
SRC_DIRS = ./ ./benchmarks/ ./concurrency_control/ ./storage/ ./system/ ./transport/ ./utils/ ./grpc/ ./grpc_system/
INCLUDE = -I. -I./benchmarks -I./concurrency_control -I./storage -I./system -I./transport -I./utils -I./grpc -I./grpc_system
CFLAGS += $(INCLUDE) -D NOGRAPHITE=1 -O3 -g -ggdb
LDFLAGS = -Wall -L./libs -pthread -lrt -std=c++0x -O3 -ljemalloc -lprotobuf
LDFLAGS += $(CFLAGS)
# Add the below line
LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
-lgrpc++_reflection\
-ldl
CPPS = $(foreach dir, $(SRC_DIRS), $(wildcard $(dir)*.cpp))
OBJS = $(CPPS:.cpp=.o)
DEPS = $(CPPS:.cpp=.d)
all:rundb
rundb : $(OBJS)
$(CC) -o $# $^ $(LDFLAGS)
-include $(OBJS:%.o=%.d)
%.d: %.cpp
$(CC) -MM -MT $*.o -MF $# $(CFLAGS) $<
%.o: %.cpp %.d
$(CC) -c $(CFLAGS) -o $# $<
.PHONY: clean
clean:
rm -f rundb *.o */*.o *.d */*.d
Step 2:
In your command prompt, you need to find the path of two files:
Path of "protobuf.pc"
Path of "grpc.pc"
You can find the path using these commands:
sudo find / -name "protobuf.pc"
Example output: /usr/local/lib/pkgconfig
sudo find / -name "grpc.pc"
Example output: /usr/lib/pkgconfig"
At last, you need to add these two paths separated by colon (:) in the environment variable "PKG_CONFIG_PATH" by running this command:
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/lib/pkgconfig"
Now, you can run your commands and proceed further.
NOTE:
In step 2, if both protobuf.pc and grpc.pc are present in the same directory,
then you need to specify only that directory in the environment variable.
Example:
sudo find / -name "protobuf.pc"
Example output: /lib64/pkgconfig
sudo find / -name "grpc.pc"
Example output: /lib64/pkgconfig
In this case, you can set environment variable as:
export PKG_CONFIG_PATH="/lib64/pkgconfig"

undefined reference to sqrt in SVM-Struct (have used -lm)

Actually, I am working with the well-known SVM-struct project (http://www.cs.cornell.edu/people/tj/svm_light/svm_struct.html)on Ubuntu 16.04. I followed the instructions in http://www.cs.cornell.edu/people/tj/svm_light/svm_multiclass.html to use SVM-multiclass, downloaded the source code and make. But I met some errors when building the project:
$ make
cd svm_light; make svm_learn_hideo_noexe
make[1]: Entering directory '/home/parallels/CLionProjects/svm_multiclass/svm_light'
make[1]: Nothing to be done for 'svm_learn_hideo_noexe'.
make[1]: Leaving directory '/home/parallels/CLionProjects/svm_multiclass/svm_light'
cd svm_struct; make svm_struct_noexe
make[1]: Entering directory '/home/parallels/CLionProjects/svm_multiclass/svm_struct'
make[1]: Nothing to be done for 'svm_struct_noexe'.
make[1]: Leaving directory '/home/parallels/CLionProjects/svm_multiclass/svm_struct'
gcc -O3 -lm -Wall svm_struct/svm_struct_learn.o svm_struct_learn_custom.o svm_struct_api.o svm_light/svm_hideo.o svm_light/svm_learn.o svm_light/svm_common.o svm_struct/svm_struct_common.o svm_struct/svm_struct_main.o -o svm_multiclass_learn
svm_light/svm_learn.o: In function `estimate_sphere':
svm_learn.c:(.text+0x6e88): undefined reference to `sqrt'
svm_light/svm_learn.o: In function `estimate_r_delta':
svm_learn.c:(.text+0x7053): undefined reference to `sqrt'
svm_light/svm_learn.o: In function `estimate_r_delta_average':
svm_learn.c:(.text+0x7b04): undefined reference to `sqrt'
svm_light/svm_learn.o: In function `length_of_longest_document_vector':
svm_learn.c:(.text+0x7b86): undefined reference to `sqrt'
svm_light/svm_learn.o: In function `incorporate_unlabeled_examples':
svm_learn.c:(.text+0x89eb): undefined reference to `sqrt'
svm_light/svm_learn.o:svm_learn.c:(.text+0xc952): more undefined references to `sqrt' follow
svm_light/svm_common.o: In function `classify_example':
svm_common.c:(.text+0x38f): undefined reference to `tanh'
svm_common.c:(.text+0x42d): undefined reference to `exp'
svm_common.c:(.text+0x4a7): undefined reference to `pow'
svm_light/svm_common.o: In function `kernel':
svm_common.c:(.text+0x870): undefined reference to `tanh'
svm_common.c:(.text+0x90d): undefined reference to `exp'
svm_common.c:(.text+0x988): undefined reference to `pow'
svm_light/svm_common.o: In function `model_length_s':
svm_common.c:(.text+0x2c8d): undefined reference to `sqrt'
svm_light/svm_common.o: In function `model_length_n':
svm_common.c:(.text+0x2f5c): undefined reference to `sqrt'
svm_light/svm_common.o: In function `cholesky_matrix':
svm_common.c:(.text+0x3c6f): undefined reference to `sqrt'
svm_light/svm_common.o: In function `find_indep_subset_of_matrix':
svm_common.c:(.text+0x3f41): undefined reference to `sqrt'
svm_light/svm_common.o: In function `single_kernel':
svm_common.c:(.text+0xc0c): undefined reference to `tanh'
svm_common.c:(.text+0xc84): undefined reference to `pow'
svm_common.c:(.text+0xcfb): undefined reference to `exp'
collect2: error: ld returned 1 exit status
Makefile:48: recipe for target 'svm_multiclass_learn' failed
make: *** [svm_multiclass_learn] Error 1
I think the Makefile has already included -lm.
# Makefile for SVM-multiclass, 03.07.04
#Use the following to compile under unix or cygwin
CC = gcc
LD = gcc
#Call 'make' using the following line to make CYGWIN produce stand-alone Windows executables
# make 'SFLAGS=-mno-cygwin'
CFLAGS = $(SFLAGS) -O3 -fomit-frame-pointer -ffast-math -Wall
LDFLAGS = $(SFLAGS) -O3 -lm -Wall
#CFLAGS = $(SFLAGS) -pg -Wall
#LDFLAGS = $(SFLAGS) -pg -lm -Wall
all: svm_multiclass_learn svm_multiclass_classify
.PHONY: clean
clean: svm_light_clean svm_struct_clean
rm -f *.o *.tcov *.d core gmon.out *.stackdump
#-----------------------#
#---- SVM-light ----#
#-----------------------#
svm_light_hideo_noexe:
cd svm_light; make svm_learn_hideo_noexe
svm_light_clean:
cd svm_light; make clean
#----------------------#
#---- STRUCT SVM ----#
#----------------------#
svm_struct_noexe:
cd svm_struct; make svm_struct_noexe
svm_struct_clean:
cd svm_struct; make clean
#-------------------------#
#---- SVM MULTICLASS ----#
#-------------------------#
svm_multiclass_classify: svm_light_hideo_noexe svm_struct_noexe svm_struct_api.o svm_struct/svm_struct_classify.o svm_struct/svm_struct_common.o svm_struct/svm_struct_main.o
$(LD) $(LDFLAGS) svm_struct_api.o svm_struct/svm_struct_classify.o svm_light/svm_common.o svm_struct/svm_struct_common.o -o svm_multiclass_classify $(LIBS)
svm_multiclass_learn: svm_light_hideo_noexe svm_struct_noexe svm_struct_api.o svm_struct_learn_custom.o svm_struct/svm_struct_learn.o svm_struct/svm_struct_common.o svm_struct/svm_struct_main.o
$(LD) $(LDFLAGS) svm_struct/svm_struct_learn.o svm_struct_learn_custom.o svm_struct_api.o svm_light/svm_hideo.o svm_light/svm_learn.o svm_light/svm_common.o svm_struct/svm_struct_common.o svm_struct/svm_struct_main.o -o svm_multiclass_learn $(LIBS)
svm_struct_api.o: svm_struct_api.c svm_struct_api.h svm_struct_api_types.h svm_struct/svm_struct_common.h
$(CC) -c $(CFLAGS) svm_struct_api.c -o svm_struct_api.o
svm_struct_learn_custom.o: svm_struct_learn_custom.c svm_struct_api.h svm_light/svm_common.h svm_struct_api_types.h svm_struct/svm_struct_common.h
$(CC) -c $(CFLAGS) svm_struct_learn_custom.c -o svm_struct_learn_custom.o
The linker collects dependencies first (svm_light/svm_learn.o) and fills them in when it sees a definition (-lm).
You seem to already have a $(LIBS) at the end of your ld invocation, so just:
LIBS += -lm
should fix it.
Other tips:
you can replace the pattern cd X; make TARGET with make -C X TARGET
you can refer to the target as $# and the first prerequisite in the dependency list as $<, so your last rule can be written as:
svm_struct_learn_custom.o: svm_struct_learn_custom.c svm_struct_api.h svm_light/svm_common.h svm_struct_api_types.h svm_struct/svm_struct_common.h
$(CC) -c $(CFLAGS) $< -o $#
where the recipe redefinition of the built-in recipe for compiling .c files, so it suffices to simply list the headers as (extra) prerequisites:
svm_struct_learn_custom.o: svm_struct_api.h svm_light/svm_common.h svm_struct_api_types.h svm_struct/svm_struct_common.h

Program not linking when compiled via a Makefile and using an external linked library

I have a makefile that I've been using to compile my shared libraries which reads in the files from different folders and then builds the objects and binaries in their own folders. The folder structure I'm using is roughly displayed below.
-Folder
|
+--API Header Files Dir
|
+--Library (.so) Project One
| +-- MakeFile Project One
| +-- src (*.cpp files)
| +-- inc (*.h files)
| +-- obj (compiled object files)
| +-- bin (compiled project)
|
+--Library (.so) Project Two
| +-- MakeFile Project Two
| +-- src (*.cpp files)
| +-- inc (*.h files)
| +-- obj (compiled object files)
| +-- bin (compiled project)
|
I've tried to put together a general makefile that can accomplish this and this post was quite nice and I've edited my original makefile to the best of my understanding to try to make this work.
One problem - while it works ok when I'm just compiling source code only, I've been trying to use it in a project where I'm linking to some external library files and it no longer works. I keep getting the following error:
collect2: ld returned 1 exit status
make: *** [bin/libTest_v1_5.o] Error 1
I've managed to set up a project in Code::Blocks to test all the project files and that compiles ok, so it's just my makefile that is incorrect. I guess I've gotten one of the rules wrong.
Here's my file:
######################################################################################
# Purpose : MakeFile for building shared library & coupled projects
#
# Date Created : 25-06-2015
# Date Modified :
#
# Note : 1. make : to build unoptimized standard build
# 2. make debug : to build with debug symbols
# 3. make release : to build with symbols stripped and optimized
#
# Usage : change the "TARGET" to your program name or else use as it is
######################################################################################
ifndef _ARCH
_ARCH := $(shell uname -m)
export _ARCH
endif # wanted to use this in my build directories but figured it's not necessary?
NAME := Test
MAJOR := 1
MINOR := 5
VERSION := v$(MAJOR)_$(MINOR)
TARGET := lib$(NAME)_$(VERSION).o
SRCEXT := cpp
SRCDIR := src
INCPATH := inc
OBJDIR := obj
BINDIR := bin
BIN_DEBUGDIR := $(BINDIR)/debug
API_DIR := /home/API/Multibody/Coupling
INCLUDES := -I. \
-I$(INCPATH) \
-I$(API_DIR)
# C++ compiler flag
CXXFLAGS := -Wall -W -march=native -c $(INCLUDES)
# Linker parameter flags
LDFLAGS := -L$(API_DIR)/lib
# Linker library flags
LDLIBS += -lCouplingClientV2_2_0
SRCS := $(shell find $(SRCDIR) -name '*.$(SRCEXT)')
SRCDIRS := $(shell find . -name '*.$(SRCEXT)' -exec dirname {} \; | uniq)
OBJS := $(patsubst %.$(SRCEXT),$(OBJDIR)/%.o,$(SRCS))
###########################################################################
# Rules to compile our files - Do not change below this line!
###########################################################################
ifeq ($(SRCEXT), cpp)
CC = $(CXX)
else
CXXFLAGS += -std=gnu99
endif
.PHONY: all debug release clean distclean
all: $(BINDIR)/$(TARGET)
# Build debug library
debug: CXXFLAGS += -g
debug: clean $(BIN_DEBUGDIR)/$(TARGET)
# strip all symbols from release verison
release: LDFLAGS += -s
release: CXXFLAGS += -O2
release: $(BINDIR)/$(TARGET)
$(BINDIR)/$(TARGET): buildrepo $(OBJS)
#mkdir -p `dirname $#`
#echo "Linking $#..."
#$(CC) $(OBJS) $(LDFLAGS) -o $#
#echo "$# sucessfully built."
$(BIN_DEBUGDIR)/$(TARGET): buildrepo $(OBJS)
#mkdir -p `dirname $#`
#echo "Linking $#..."
#$(CC) $(OBJS) $(LDFLAGS) -o $# $(LDLIBS)
#echo "$# sucessfully built."
$(OBJDIR)/%.o: %.$(SRCEXT)
#echo "Generating dependencies for $<..."
#$(call make-depend,$<,$#,$(subst .o,.d,$#))
#echo "Compiling $<..."
#$(CC) $(CXXFLAGS) $< -c -o $#
clean:
$(RM) -r $(OBJDIR)
distclean: clean
$(RM) -r $(BINDIR)/$(TARGET)
$(RM) -r $(BIN_DEBUGDIR)/$(TARGET)
buildrepo:
#$(call make-repo)
define make-repo
for dir in $(SRCDIRS); \
do \
mkdir -p $(OBJDIR)/$$dir; \
done
endef
# usage: $(call make-depend,source-file,object-file,depend-file)
define make-depend
$(CC) -MM \
-MMD \
-MF $3 \
-MP \
-MT $2 \
$(CXXFLAGS) \
$(LDFLAGS) \
$1
endef
Any comments on how to improve the makefile would be great. Any answers as to what I'm doing wrong in the linking would be even better!!
Update:
Here's the output from code::blocks for a successfully compiled project from the exact same source code and library. My problem only relates to the makefile - not what's defined anywhere in the project source code or API files.
-------------- Build: Release in Test (compiler: GNU GCC Compiler)---------------
g++ -Wall -fexceptions -O2 -Wfatal-errors -Wall -I../Multibody/EDEMCoupling -c /home/API/Multibody/EPT/src/EPT_Consolidation_Damped_v11.cpp -o obj/Release/Multibody/EPT/src/EPT_Consolidation_Damped_v11.o
g++ -L../Multibody/EDEMCoupling/lib -o bin/Release/EPT_Test obj/Release/Multibody/EPT/src/EPT_Consolidation_Damped_v11.o -s /home/API/Multibody/EDEMCoupling/lib/libEDEMCouplingClientV2_2_0.so
Output size is 48.21 KB
Process terminated with status 0 (0 minutes, 6 seconds)
Makefile Output:
Here's the terminal output after calling make. It never gets past the stage of compiling the object file from the source.cpp (This is a very simple project and has only a single cpp file in it). I don't really understand why since this file was working perfectly for all the projects that compiled shared libraries - I've just removed -shared and -fPIC from the flags.
*Generating dependencies for src/EPT_Consolidation_Damped_v11.cpp...
Compiling src/EPT_Consolidation_Damped_v11.cpp...
src/EPT_Consolidation_Damped_v11.cpp: In function ‘int main()’:
src/EPT_Consolidation_Damped_v11.cpp:199: warning: deprecated conversion from string constant to ‘char*’
/home/API/Multibody/EDEMCoupling/ApiTypes.h: At global scope:
/home/API/Multibody/EDEMCoupling/ApiTypes.h:193: warning: ‘const char* NApi::delim()’ defined but not used
Linking bin/Test_v1_5.o...
obj/src/EPT_Consolidation_Damped_v11.o: In function `main':
EPT_Consolidation_Damped_v11.cpp:(.text+0x546): undefined reference to `NApiEDEM::IEDEMCoupling::IEDEMCoupling()'
EPT_Consolidation_Damped_v11.cpp:(.text+0x555): undefined reference to `NApiEDEM::IEDEMCoupling::initialiseCoupling()'
EPT_Consolidation_Damped_v11.cpp:(.text+0x5e3): undefined reference to `NApiEDEM::IEDEMCoupling::connectCoupling(bool, char*)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x6e0): undefined reference to `NApiEDEM::IEDEMCoupling::getGeometryId(char const*, int&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x71b): undefined reference to `NApiEDEM::IEDEMCoupling::getGeometryId(char const*, int&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x756): undefined reference to `NApiEDEM::IEDEMCoupling::getGeometryId(char const*, int&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x16c4): undefined reference to `NApiEDEM::IEDEMCoupling::setGridCellSize(double const&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x16e9): undefined reference to `NApiEDEM::IEDEMCoupling::setNumberOfCores(int const&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x1702): undefined reference to `NApiEDEM::IEDEMCoupling::getEDEMTimeStep(double&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x1725): undefined reference to `NApiEDEM::IEDEMCoupling::getNumberOfTimesteps(unsigned int&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x175c): undefined reference to `NApiEDEM::IEDEMCoupling::getEDEMTime(double&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x17ef): undefined reference to `NApiEDEM::IEDEMCoupling::getEDEMTimesteps(double*, unsigned int&, unsigned int)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x1d66): undefined reference to `NApiEDEM::IEDEMCoupling::setEDEMTime(double const&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x1d7f): undefined reference to `NApiEDEM::IEDEMCoupling::getEDEMTime(double&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x1eb7): undefined reference to `NApiEDEM::IEDEMCoupling::setEDEMTime(double const&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x1ed0): undefined reference to `NApiEDEM::IEDEMCoupling::getEDEMTime(double&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x21e7): undefined reference to `NApiEDEM::IEDEMCoupling::getGeometryPosition(int, NApiEDEM::C3dValue&, NApiEDEM::C3x3Matrix&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x221a): undefined reference to `NApiEDEM::IEDEMCoupling::getGeometryPosition(int, NApiEDEM::C3dValue&, NApiEDEM::C3x3Matrix&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x2358): undefined reference to `NApiEDEM::IEDEMCoupling::getGeometryTranslation(int, NApiEDEM::C3dValue&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x2562): undefined reference to `NApiEDEM::IEDEMCoupling::getGeometryVelocity(int, NApiEDEM::C3dValue&, NApiEDEM::C3dValue&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x2710): undefined reference to `NApiEDEM::IEDEMCoupling::getGeometryTranslation(int, NApiEDEM::C3dValue&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x291a): undefined reference to `NApiEDEM::IEDEMCoupling::getGeometryVelocity(int, NApiEDEM::C3dValue&, NApiEDEM::C3dValue&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x2afd): undefined reference to `NApiEDEM::IEDEMCoupling::getGeometryForces(int, NApiEDEM::C3dValue&, NApiEDEM::C3dValue&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x2b6e): undefined reference to `NApiEDEM::IEDEMCoupling::getGeometryForces(int, NApiEDEM::C3dValue&, NApiEDEM::C3dValue&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x2c0a): undefined reference to `NApiEDEM::IEDEMCoupling::removeGeometry(char const*)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x2c28): undefined reference to `NApiEDEM::IEDEMCoupling::showSimulator()'
EPT_Consolidation_Damped_v11.cpp:(.text+0x3b21): undefined reference to `NApiEDEM::IEDEMCoupling::selectGeometrySection(char const*, int&)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x3b39): undefined reference to `NApiEDEM::IEDEMCoupling::removeGeometry(char const*)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x3b48): undefined reference to `NApiEDEM::IEDEMCoupling::showSimulator()'
EPT_Consolidation_Damped_v11.cpp:(.text+0x3fd5): undefined reference to `NApiEDEM::IEDEMCoupling::isConnected() const'
EPT_Consolidation_Damped_v11.cpp:(.text+0x4059): undefined reference to `NApiEDEM::IEDEMCoupling::setGeometryMotion(int, NApiEDEM::C3dValue const&, NApiEDEM::C3x3Matrix const&, NApiEDEM::C3dValue const&, NApiEDEM::C3dValue const&, double, bool)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x40bd): undefined reference to `NApiEDEM::IEDEMCoupling::setGeometryMotion(int, NApiEDEM::C3dValue const&, NApiEDEM::C3x3Matrix const&, NApiEDEM::C3dValue const&, NApiEDEM::C3dValue const&, double, bool)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x40f4): undefined reference to `NApiEDEM::IEDEMCoupling::isConnected() const'
EPT_Consolidation_Damped_v11.cpp:(.text+0x4119): undefined reference to `NApiEDEM::IEDEMCoupling::simulate(double const&, double)'
EPT_Consolidation_Damped_v11.cpp:(.text+0x4dbb): undefined reference to `NApiEDEM::IEDEMCoupling::~IEDEMCoupling()'
EPT_Consolidation_Damped_v11.cpp:(.text+0x4dd1): undefined reference to `NApiEDEM::IEDEMCoupling::~IEDEMCoupling()'
collect2: ld returned 1 exit status
make: *** [bin/Test_v1_5.o] Error 1*

Build brief module

I trying to build brief software. Firstly I create the ./lib/libbrief.so, and secondly I am trying to build main file. The makefile which included in .zip file:
CC=g++
SOURCES=main.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=main
//#Only enable -msse4.2 on CPUs supporting the POPCNT instruction
CFLAGS = -Wall -DNDEBUG -O3 -march=nocona #-msse4.2
//#CFLAGS = -Wall -DDEBUG -g -O0 -fno-inline-functions
LDFLAGS = -Wl
//# BRIEF
CFLAGS += -I../brief/include
LDFLAGS += -L../brief/lib -lbrief
//# OpenCV
CFLAGS += `pkg-config opencv --cflags`
LDFLAGS += `pkg-config opencv --libs`
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $#
.cpp.o:
$(CC) -g -c $(CFLAGS) $< -o $#
clean:
rm -f $(OBJECTS) $(EXECUTABLE) matches.png
However I am getting errors, related with opencv. The errors found:
g++ -Wl -L../brief/lib -lbrief `pkg-config opencv --libs` main.o -o main
main.o: In function `~BRIEF':
Desktop/asdf/brief_v1.0/test_app/../brief/include/brief/BRIEF.hpp:203:
undefined reference to `cvReleaseImage'
Desktop/asdf/brief_v1.0/test_app/../brief/include/brief/BRIEF.hpp:204:
undefined reference to `cvReleaseImage'
main.o: In function `BRIEF':
Desktop/asdf/brief_v1.0/test_app/../brief/include/brief/BRIEF.hpp:156:
undefined reference to `cvCreateImage'
Desktop/asdf/brief_v1.0/test_app/../brief/include/brief/BRIEF.hpp:157:
undefined reference to `cvCreateImage'
main.o: In function `TestSampler<signed char>::sampleGaussian(signed char*, int, int)'
main.o: In function `BRIEF':
Desktop/asdf/brief_v1.0/test_app/../brief/include/brief/BRIEF.hpp:156:
undefined reference to `cvCreateImage'
Desktop/asdf/brief_v1.0/test_app/../brief/include/brief/BRIEF.hpp:157:
undefined reference to `cvCreateImage'
main.o: In function `TestSampler<signed char>::sampleGaussian(signed char*, int, int)':
main.o: In function `BRIEF::writeTests(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&) const':
Desktop/asdf/brief_v1.0/test_app/../brief/include/brief/BRIEF.hpp:511:
undefined reference to `utils::stdoutError(std::basic_string<char,
std::char_traits<char>,
std::allocator<char> >, char const*, int, char const*)'
main.o: In function `BRIEF::readTests(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&)':
Desktop/asdf/brief_v1.0/test_app/../brief/include/brief/BRIEF.hpp:524:
undefined reference to `utils::stdoutError(std::basic_string<char,
std::char_traits<char>,
std::allocator<char> >, char const*, int, char const*)'
main.o: In function `detectSURF':
Desktop/asdf/brief_v1.0/test_app/main.cpp:92: undefined reference to
`cvCreateMemStorage'
Desktop/asdf/brief_v1.0/test_app/main.cpp:101: undefined reference to
`cvExtractSURF'
Desktop/asdf/brief_v1.0/test_app/main.cpp:106: undefined reference to
`cvGetSeqElem'
main.o: In function `timeDescription(int)':
Desktop/asdf/brief_v1.0/test_app/main.cpp:201: undefined reference to
`cvLoadImage'
Desktop/asdf/brief_v1.0/test_app/main.cpp:214: undefined reference to
`cvReleaseImage'
main.o: In function `~BRIEF':
What have to do to build proper the main.cpp?
You must list all the object files on the link like before the libraries that they use.
See, for example, Why does the order in which libraries are linked sometimes cause errors in GCC?

undefined reference with boost when I try to compile

i have lot of errors when i try to compile my server with boost.
Here, this is my makefile :
NAME = serveur
SRCS = Serveur/main.cpp \
Serveur/Client.cpp \
Serveur/Commande.cpp \
Serveur/My_exception.cpp \
Serveur/Network.cpp \
Serveur/Server.cpp
#####################################################
OBJS = $(SRCS:.cpp=.o)
CC = g++
RM = rm -f
CFLAGS = -g -W -Wall -Werror
INCL = ./Serveur/boost_1_47_0
LIB = ./Serveur/boost_1_47_0/stage/lib/
NLIB = -lboost_system -lboost_system-mt -lboost_filesystem -lboost_filesystem-mt
#####################################################
$(NAME) : $(OBJS)
#$(CC) $(OBJS) -I$(INCL) -L$(LIB) $(NLIB) -o $(NAME)
#printf "\n \033[33m[Message]\033[39m Compilation under Linux done\n\n"
.cpp.o :
#$(CC) $(CFLAGS) -I$(INCL) -L$(LIB) $(NLIB) -c $< -o $#
#printf " \033[34m[Compilation]\033[39m %s\n" $<
re : fclean all
all : $(NAME)
clean :
#$(RM) *~ $(OBJS)
#printf " \033[31m[Delete] \033[39m%s\n" $(OBJS)
fclean : clean
#$(RM) $(NAME)
#printf "\n \033[31m[Delete] \033[39m%s\n\n" $(NAME)
After "googling" i found that it's necessary to put -lboost_filesystem but it's not working again and there are next errors :
Serveur/main.o: In function `__static_initialization_and_destruction_0':
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
Serveur/main.o: In function `error_code':
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:315: undefined reference to `boost::system::system_category()'
Serveur/main.o: In function `boost::asio::error::get_system_category()':
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/asio/error.hpp:216: undefined reference to `boost::system::system_category()'
Serveur/Client.o: In function `__static_initialization_and_destruction_0':
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
Serveur/Network.o: In function `__static_initialization_and_destruction_0':
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
Serveur/Server.o: In function `__static_initialization_and_destruction_0':
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
make: *** [serveur] Error 1
Anyone know why it's not working?
boost::filesystem depends on boost::system, so you'll have to add -lboost_system, also.
I am using cygwin and the solution to this problem was linking the libraries
libboost_filesystem-mt
libboost_system-mt
The invocation of the linker looked like this:
g++ -o "bin.exe" ./src/reader.o ./src/bin.o -llibboost_filesystem-mt -llibboost_system-mt