undefined reference with boost when I try to compile - c++

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

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"

Linker Error when compiling with static library [duplicate]

This question already has answers here:
Why does the order in which libraries are linked sometimes cause errors in GCC?
(9 answers)
Closed 6 years ago.
I have a project with several .cpp and .h files, and I am trying to split the source into core / generic stuff, and application specific code. Based on that, I separated the code files into a Common folder and compiled it as a library. Below is the Makefile for that lib:
CFLAGS=-std=c++11 -g -c -pedantic -Wall -Wextra -I../boost_1_57_0 -L../boost_1_57_0/stage/lib
SOURCES = $(wildcard *.cpp)
OBJECTS=$(SOURCES:.cpp=.o)
OUTPUTFILE=libcommon.a
all: $(OUTPUTFILE)
$(OUTPUTFILE): $(OBJECTS)
ar rcs $(OUTPUTFILE) $(OBJECTS)
.cpp.o:
$(CC) $(CPPFLAGS) $(CFLAGS) $< -o $# $(GPROF)
clean:
rm -f $(OBJECTS) $(OUTPUTFILE)
Then I created a sample main file just to try out the compilation of an app using that library.
Here is the code of the main source file:
#include "../Common/Functions.h"
#include "../Common/Logger.h"
int main() {
Logger::Init(false, false);
Logger::Debug("Test");
string path = Functions::GetAppPath();
Logger::Debug("App Path: ", path.c_str());
return 0;
}
The functions file that is being referenced uses boost, and here is the makefile for this app that uses the library:
CC=g++
CFLAGS=-Wl,--verbose -std=c++11 -g -c -pedantic -Wall -Wextra -I../boost_1_57_0 -L../boost_1_57_0/stage/lib
LDFLAGS=-I../boost_1_57_0 -L../boost_1_57_0/stage/lib -L../boost_libs/lib -L/usr/lib64 -L/usr/kerberos/lib -L/usr/lib -L../Common
LIBS=-lz -lkrb5 -lk5crypto -lcom_err -lresolv -lm -lpthread -lrt -lboost_system -lboost_filesystem -lboost_thread -lboost_date_time -rdynamic -lcurl -lcommon
SOURCES = $(wildcard *.cpp)
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=testApp
GPROF=-pg
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $# $(LIBS) $(GPROF)
.cpp.o:
$(CC) $(CPPFLAGS) $(CFLAGS) $< -o $# $(GPROF)
clean:
rm -rf *o $(OBJECTS)
When I try to compile, I get the following errors, complaining about undefined references to boost:
g++ -Wl,--verbose -std=c++11 -g -c -pedantic -Wall -Wextra -I../boost_1_57_0 -L../boost_1_57_0/stage/lib main.cpp -o main.o -pg
g++ -I../boost_1_57_0 -L../boost_1_57_0/stage/lib -L../boost_libs/lib -L/usr/lib64 -L/usr/kerberos/lib -L/usr/lib -L../Common main.o -o testApp -lz -lkrb5 -lk5crypto -lcom_err -lresolv -lm -lpthread -lrt -lboost_system -lboost_filesystem -lboost_thread -lboost_date_time -rdynamic -lcurl -lcommon -pg
../Common/libcommon.a(Functions.o): In function `Functions::GetAppPath()':
/media/software/Robots/Common/Functions.cpp:43: undefined reference to `boost::filesystem::path::parent_path() const'
../Common/libcommon.a(Functions.o): In function `boost::filesystem::initial_path()':
/media/software/Robots/Common/../boost_1_57_0/boost/filesystem/operations.hpp:583: undefined reference to `boost::filesystem::detail::initial_path(boost::system::error_code*)'
../Common/libcommon.a(Functions.o): In function `boost::filesystem::system_complete(boost::filesystem::path const&)':
/media/software/Robots/Common/../boost_1_57_0/boost/filesystem/operations.hpp:655: undefined reference to `boost::filesystem::detail::system_complete(boost::filesystem::path const&, boost::system::error_code*)'
../Common/libcommon.a(Functions.o): In function `unsigned short boost::date_time::month_str_to_ushort<boost::gregorian::greg_month>(std::string const&)':
/media/software/Robots/Common/../boost_1_57_0/boost/date_time/date_parsing.hpp:67: undefined reference to `boost::gregorian::greg_month::get_month_map_ptr()'
../Common/libcommon.a(Logger.o): In function `Logger::Cleanup()':
/media/software/Robots/Common/Logger.cpp:84: undefined reference to `boost::thread::interrupt()'
../Common/libcommon.a(Logger.o): In function `Logger::InitFile(std::string, bool, std::_Ios_Openmode)':
/media/software/Robots/Common/Logger.cpp:186: undefined reference to `boost::filesystem::path::parent_path() const'
/media/software/Robots/Common/Logger.cpp:187: undefined reference to `boost::filesystem::path::parent_path() const'
../Common/libcommon.a(Logger.o): In function `Logger::Process()':
/media/software/Robots/Common/Logger.cpp:241: undefined reference to `boost::this_thread::interruption_point()'
../Common/libcommon.a(Logger.o): In function `boost::detail::thread_data_base::thread_data_base()':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/pthread/thread_data.hpp:143: undefined reference to `vtable for boost::detail::thread_data_base'
../Common/libcommon.a(Logger.o): In function `boost::thread::start_thread()':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/detail/thread.hpp:179: undefined reference to `boost::thread::start_thread_noexcept()'
../Common/libcommon.a(Logger.o): In function `boost::thread::~thread()':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/detail/thread.hpp:254: undefined reference to `boost::thread::detach()'
../Common/libcommon.a(Logger.o): In function `boost::thread::get_id() const':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/detail/thread.hpp:741: undefined reference to `boost::thread::native_handle()'
../Common/libcommon.a(Logger.o): In function `boost::thread::join()':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/detail/thread.hpp:767: undefined reference to `boost::thread::join_noexcept()'
../Common/libcommon.a(Logger.o): In function `boost::filesystem::exists(boost::filesystem::path const&)':
/media/software/Robots/Common/../boost_1_57_0/boost/filesystem/operations.hpp:404: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
../Common/libcommon.a(Logger.o): In function `boost::filesystem::create_directories(boost::filesystem::path const&)':
/media/software/Robots/Common/../boost_1_57_0/boost/filesystem/operations.hpp:523: undefined reference to `boost::filesystem::detail::create_directories(boost::filesystem::path const&, boost::system::error_code*)'
../Common/libcommon.a(Logger.o): In function `boost::detail::thread_data<void (*)()>::~thread_data()':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/detail/thread.hpp:90: undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
../Common/libcommon.a(Logger.o):(.rodata._ZTIN5boost6detail11thread_dataIPFvvEEE[_ZTIN5boost6detail11thread_dataIPFvvEEE]+0x10): undefined reference to `typeinfo for boost::detail::thread_data_base'
collect2: error: ld returned 1 exit status
Needless to say that the project as a whole compiles with no issue.
This is my first attempt at building a c++ linux library and using it in another application, so I might be doing a rookie mistake, so bear that in mind.
Help is very much appreciated.
Thank you.
The order of libraries on the command line is significant to the linker. It processes libraries from left to right, resolving as-yet unresolved references already known to it against any functions provided by the current library.
Moreover, and particularly relevant here, if a given library contains references to functions that it does not itself provide then the linker does not resolve those against libraries it has already processed. That's why you have unresolved references: you have -lcommon last among your libraries, so function references therein will be resolved against only the C standard library.
It is valid to list libraries more than once in the link command, and sometimes that is needed, but in this case I think it makes sense simply to put -lcommon as the first library instead of the last. That will resolve the issue. You can even conceptualize this as putting the library most closely related to the main program closest to it in the link command.

Modifying CUDA and cpp Makefile

I am trying to modify my makefile to support .cpp and .cu, however, I keep getting an error such as:
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o(.text+0x20): error: undefined reference to 'main'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'camera'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'camera'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'camera'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'camera'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'sphereCount'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'sphereCount'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'sphereCount'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'spheres'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'spheres'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'sphereCount'
hostCode.o:displayfunc.cpp:function idleFunc(): error: undefined reference to 'updateRendering()'
hostCode.o:displayfunc.cpp:function reshapeFunc(int, int): error: undefined reference to 'reInitCamera(bool)'
hostCode.o:displayfunc.cpp:function keyFunc(unsigned char, int, int): error: undefined reference to 'reInitCamera(bool)'
Makefile
CXX = g++
NVCC = nvcc -ccbin $(CXX)
INCLUDES := -I/home/cuda_app/inc/
LDFLAGS = -lGL -lGLU -lglut -lpthread
ALL:= test
test: hostCode.o deviceCode.o
$(NVCC) $(INCLUDES) -o $# $< $(LDFLAGS)
deviceCode.o: SmallPtCUDA.cu
$(NVCC) $(INCLUDES) -o $# -c $< $(LDFLAGS)
hostCode.o: displayfunc.cpp
$(CXX) $(INCLUDES) -o $# -c $< $(LDFLAGS)
clean:
rm -rf *.o $(ALL)
How can I compile both .cpp and .cu?
Can anybody help with this please? Thanks
When asking a question about build errors, it's always best to include not just the errors but also the command invoking the compiler or linker. With errors like this the problem is there; seeing the error messages is helpful but not definitive.
In your case the problem is your link command is incorrect in your makefile:
test: hostCode.o deviceCode.o
$(NVCC) $(INCLUDES) -o $# $< $(LDFLAGS)
You are using $< here which expands to just the first prerequisite. If you'd included the link line and examined it you'd see that the deviceCode.o file is not present on the link line. You want your link command to look like this:
test: hostCode.o deviceCode.o
$(NVCC) $(INCLUDES) -o $# $^ $(LDFLAGS)
Using $^ which expands to all the prerequisites.
Also, just a note that by convention LDFLAGS contains linker options like -L, and LDLIBS is used for linker options like -l. However your setup will work (it's just not conventional).

"undefined reference to" in MakeFile

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)).

undefined reference to `cvGetOptimalDFTSize'

I am working with Opencv-2.1 on arm-linux. I am using arm-linux-g++ compiler. I ran in to a strange error during linking. Before talking about the error, I will post my make commands
CC = arm-linux-g++
COMPILEFLAGS = -Wall -fPIC -c -O2 -I./
OUT_DLL = libLensFinder.so
DLL_FLAGS = -shared -o
OBJS = SegmentRegions.o
OBJS2 = EdgeDetection.o
OBJS3 = AnalyseRegions.o
OBJS4 = global.o
LINK_FLAGS = -L./ -lLensFinder
LINK_FLAGS_2 = -L./ -lTwoX
INCPATH = -I/home/zwang/ravi/opencv_include21/opencv/ -I.
all :
$(CC) $(COMPILEFLAGS) $(INCPATH) global.cpp -o global.o
$(CC) $(COMPILEFLAGS) $(INCPATH) EdgeDetection.cpp -o EdgeDetection.o
$(CC) $(COMPILEFLAGS) $(INCPATH) SegmentRegions.cpp -o SegmentRegions.o
$(CC) $(COMPILEFLAGS) $(INCPATH) AnalyseRegions.cpp -o AnalyseRegions.o
$(CC) $(OBJS) $(OBJS2) $(OBJS3) $(OBJS4) $(DLL_FLAGS) ./$(OUT_DLL) -L/home/zwang/ravi/opencv_include21/lib -lcvaux -lcxcore -lhighgui -lcv -lml -lcxts -lrt
$(CC) $(COMPILEFLAGS) $(INCPATH) sample.cpp
#$(CC) $(LINK_FLAGS) sample.o -o sample
$(CC) $(LINK_FLAGS) $(LINK_FLAGS_2) sample.o -o sample
Everything works fine till the end. During the last command i.e., while creating executable file I am getting the following error.
arm-linux-g++ -L./ -lLensFinder -L./ -lTwoX sample.o -o sample
.//libLensFinder.so: undefined reference to `spotrs_'
.//libLensFinder.so: undefined reference to `cvGetOptimalDFTSize'
.//libLensFinder.so: undefined reference to `dgels_'
.//libLensFinder.so: undefined reference to `dgelsd_'
.//libLensFinder.so: undefined reference to `dgesdd_'
.//libLensFinder.so: undefined reference to `cvMulSpectrums'
.//libLensFinder.so: undefined reference to `sgesdd_'
.//libLensFinder.so: undefined reference to `sgetri_'
.//libLensFinder.so: undefined reference to `cvDFT'
.//libLensFinder.so: undefined reference to `dgesv_'
.//libLensFinder.so: undefined reference to `dgetrf_'
.//libLensFinder.so: undefined reference to `dsyevr_'
.//libLensFinder.so: undefined reference to `sgels_'
.//libLensFinder.so: undefined reference to `spotrf_'
.//libLensFinder.so: undefined reference to `sgetrf_'
.//libLensFinder.so: undefined reference to `dpotrf_'
.//libLensFinder.so: undefined reference to `dpotri_'
.//libLensFinder.so: undefined reference to `sgesv_'
.//libLensFinder.so: undefined reference to `ssyevr_'
.//libLensFinder.so: undefined reference to `dpotrs_'
.//libLensFinder.so: undefined reference to `sgelsd_'
.//libLensFinder.so: undefined reference to `spotri_'
.//libLensFinder.so: undefined reference to `dgetri_'
collect2: ld returned 1 exit status
make: *** [all] Error 1
Two of the undefined references are cvMulSpectrums' andcvGetOptimalDFTSize', which I guess is due to opencv. And I have no clue on other undefined reference. I think I have linked every library. But still can't understand how to solve this. Any suggestions? FYI, the code is working on visual studio.
Those symbols are defined in the libopencv_core library file.
Notice how the command arm-linux-g++ -L./ -lLensFinder -L./ -lTwoX sample.o -o sample doesn't link sample with any opencv library, so it makes sense that the linking process complains about it.
You probably should adjust your build to do something like:
arm-linux-g++ sample.o -o sample -L./ -lLensFinder -L./ -lTwoX -L/home/zwang/ravi/opencv_include21/lib -lcvaux -lcxcore -lhighgui -lcv -lml -lcxts -lrt