I'm trying to compile a piece of code that creates a TNonblockingServer and I get the following compile error. Any idea what's wrong?
something_server.cpp:(.text+0x1ad): undefined reference to `apache::thrift::server::TNonblockingServer::serve()'
something_server.cpp:(.text+0x1c1): undefined reference to `apache::thrift::server::TNonblockingServer::~TNonblockingServer()'
something_server.cpp:(.text+0x280): undefined reference to `apache::thrift::server::TNonblockingServer::~TNonblockingServer()'
I performed the steps outlined here while installing thrift.
http://thrift.apache.org/docs/install/os_x/
Here's my makefile
GEN_SRC := Something.cpp something_constants.cpp something_types.cpp
GEN_OBJ := $(patsubst %.cpp,%.o, $(GEN_SRC))
THRIFT_DIR := /usr/local/include/thrift
BOOST_DIR := /usr/local/include
INC := -I$(THRIFT_DIR) -I$(BOOST_DIR)
.PHONY: all clean
all: something_server something_client
%.o: %.cpp
$(CXX) -Wall -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H $(INC) -c $< -o $#
something_server: something_server.o $(GEN_OBJ)
$(CXX) $^ -o $# -L/usr/local/lib -lthrift
something_client: something_client.o $(GEN_OBJ)
$(CXX) $^ -o $# -L/usr/local/lib -lthrift
clean:
$(RM) *.o something_server something_client
As pointed out by Dmitry, if we add -lthriftnb to compiling command, it solves the problem. These missing references are found in libthriftnb.so This file has references to libevent. So I had to include -levent to compiling command. Without -levent linker generates multiple error messages. Some of the messages are as follows -
/usr/local/lib/libthriftnb.so: undefined reference to `event_set'
/usr/local/lib/libthriftnb.so: undefined reference to `evbuffer_new'
/usr/local/lib/libthriftnb.so: undefined reference to `evhttp_free'
.
.
.
.
/usr/local/lib/libthriftnb.so: undefined reference to `event_del'
Related
For context, I'm trying to compile source to a 32-bit executable for Windows using a Linux machine. I'm using the current mingw-w64 via apt-get. Here's the project I'm trying to compile ftp://ftp.thegpm.org/projects/tandem/source. More specifically the 17-02-01 zip files contain the source I'm interested in.
My first attempt was to just edit with the Makefile_ubuntu under the tandem-linux and swap out the gcc with the one provided by mingw and fix header reference issues that cropped up by adding #includes to .cpp files that threw errors. Super hacky. Can someone show me a brighter path?
Here's the makefile I'm using:
#makefile for c++ programs
#change the name of the executable to use for "any" project
EXECUTABLE = ../bin/tandem.exe
#EXECUTABLE = ../bin/p3.exe
LINKCC = $(CXX)
#CXXFLAGS denotes flags for the C++ compiler
CXX = /usr/bin/i686-w64-mingw32-g++-win32
#uncomment this line if you are using gcc 4.x
CXXFLAGS = -m32 -std=gnu++11
#CXXFLAGS = -w -O2 -DGCC4_3
#CXXFLAGS = -w -O2 -DGCC4_3 -DX_P3
#ubuntu 64 bit version
#LDFLAGS = -L/usr/lib/x86_64-linux-gnu/libexpat.a
LDFLAGS = -lpthread -lm -L/usr/lib/x86_64-linux-gnu/libexpat.a
#LDFLAGS = -lpthread -L/usr/lib -lm -lexpat
SRCS := $(wildcard *.cpp)
OBJS := $(patsubst %.cpp,%.o,$(wildcard *.cpp))
DEPS := $(patsubst %.o,%.d,$(OBJS))
all: $(EXECUTABLE)
#define the components of the program, and how to link them
#these components are defined as dependencies; that is they must be up-to-date before the code is linked
$(EXECUTABLE): $(DEPS) $(OBJS)
$(LINKCC) $(CXXFLAGS) -o $(EXECUTABLE) $(OBJS) $(LDFLAGS)
#specify the dep files depend on the cpp files
%.d: %.cpp
$(CXX) -M $(CXXFLAGS) $< > $#
$(CXX) -M $(CXXFLAGS) $< | sed s/\\.o/.d/ > $#
clean:
-rm $(OBJS) $(EXECUTABLE) $(DEPS) *~
explain:
#echo "The following info represents the program:"
#echo "Final exec name: $(EXECUTABLE)"
#echo "Source files: $(SRCS)"
#echo "Object files: $(OBJS)"
#echo "Dep files: $(DEPS)"
depend: $(DEPS)
#echo "Deps are now up-to-date."
-include $(DEPS)
And here is the error(s):
sudo make -f Makefile_ubuntu
/usr/bin/i686-w64-mingw32-g++-win32 -m32 -std=gnu++11 -o ../bin/tandem.exe tandem.o p3mprocess.o saxmzdatahandler.o mspectrumcondition.o masscalc.o mprocess.o mreport.o mscore_tandem.o loadmspectrum.o mplugin.o msequenceserver.o saxtaxhandler.o msequencecollection.o mscore.o mrefine.o xmltaxonomy.o mbiomlreport.o saxtandeminputhandler.o saxhandler.o msequtilities.o base64.o saxmodhandler.o mtermmods.o xmlparameter.o saxsaphandler.o saxmzxmlhandler.o saxmzmlhandler.o mxxcleavage.o p3msequenceserver.o mzid_report.o saxbiomlhandler.o p3.o mpmods.o saxgamlhandler.o stdafx.o MSNumpress.o mpam.o -lpthread -lm -L/usr/lib/x86_64-linux-gnu/libexpat.a
saxhandler.o:saxhandler.cpp:(.text+0x100): undefined reference to `XML_ParserCreate'
saxhandler.o:saxhandler.cpp:(.text+0x11d): undefined reference to `XML_SetUserData'
saxhandler.o:saxhandler.cpp:(.text+0x13b): undefined reference to `XML_SetElementHandler'
saxhandler.o:saxhandler.cpp:(.text+0x151): undefined reference to `XML_SetCharacterDataHandler'
saxhandler.o:saxhandler.cpp:(.text+0x1cf): undefined reference to `XML_ParserFree'
saxhandler.o:saxhandler.cpp:(.text+0x344): undefined reference to `XML_Parse'
saxhandler.o:saxhandler.cpp:(.text+0x37f): undefined reference to `XML_Parse'
saxhandler.o:saxhandler.cpp:(.text+0x3bd): undefined reference to `XML_GetErrorCode'
saxhandler.o:saxhandler.cpp:(.text+0x3d4): undefined reference to `XML_GetCurrentLineNumber'
collect2: error: ld returned 1 exit status
Makefile_ubuntu:33: recipe for target '../bin/tandem.exe' failed
make: *** [../bin/tandem.exe] Error 1
You are (incorrectly) linking with /usr/lib/x86_64-linux-gnu/libexpat.a which is a Linux library (in ELF format). You need to get some Windows version of it.
BTW -L/usr/lib/x86_64-linux-gnu/libexpat.a is incorrect. Since -L should give a directory not a library to link
At last, recent versions of Windows might have WSL which could be useful to you (you'll compile a Linux, mostly statically linked, executable, and it might run on the command line on Windows).
I downloaded AESCrypt library in order to compile with MingW:
https://github.com/paulej/AESCrypt/tree/master/Windows
I receive this error message:
C:\Users\MyPC\AppData\Local\Temp\cclSPvvW.o:aescrypt.c:(.text+0xa2): undefined re
ference to `sha256_starts(sha256_context*)'
C:\Users\MyPC\AppData\Local\Temp\cclSPvvW.o:aescrypt.c:(.text+0xc0): undefined re
ference to `sha256_update(sha256_context*, unsigned char*, unsigned long)'
C:\Users\MyPC\AppData\Local\Temp\cclSPvvW.o:aescrypt.c:(.text+0x815): undefined r
eference to `aes_encrypt(aes_context*, unsigned char*, unsigned char*)'
C:\Users\MyPC\AppData\Local\Temp\cclSPvvW.o:aescrypt.c:(.text+0x829): undefined r
eference to `sha256_update(sha256_context*, unsigned char*, unsigned long)'
C:/Program Files (x86)/mingw-w64/i686-6.1.0-posix-dwarf-rt_v5-rev1/mingw32/bin/.
./lib/gcc/i686-w64-mingw32/6.1.0/../../../../i686-w64-mingw32/lib/../lib/libming
w32.a(lib32_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x39): undefined refe
rence to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
I am on Windows 7 x64, I am using MingW-w64 6.1.0.
This kind of error means you forgot to link the file containing the code of the missing symbol. It is usually a .o or .lib/.a file.
In your case one of the symbols is: sha256_starts(sha256_context*), which is probably in sha256.o. Check the actual link command and make sure it includes this file or the library which includes it.
A makefile like this should make the trick:
COMP = gcc
RM = rm -f
OBJS = aes.o sha256.o stdafx.o AESCrypt.o AESCryptShellExt.o AESCryptWorkerThreads.o BufferedFile.o ErrorHandling.o PasswdDialog.o ProgressDialog.o
LDFLAGS = -mwindows
SERVERLDFLAGS =
TARGET = aes.exe
all : $(TARGET)
$(TARGET) : $(OBJS)
$(COMP) $(LDFLAGS) $(DEBUGFLAGS) -o $(TARGET) $^
clean :
$(RM) *.o
%.o : %.c %.h
$(COMP) $(CFLAGS) -c $<
%.o : %.cpp %.h
$(COMP) $(CFLAGS) -c $<
Below is my makefile
#Makefile for beaglebone
#General tools
CC=gcc
CFLAGS = -g -Wall
RM = rm -fr
TARGET = beaglebone
# Source locations
BACNET_CORE = ../../src
BACNET_INCLUDE = ../../include
BACNET_HANDLER = ../../demo/handler
BACNET_OBJECT = ../../demo/object
BACNET_DEMO = ../../demo
# local files for this project
CSRC = main.c arcnet.c bip-init.c dlmstp.c dlmstp_linux.c ethernet.c rs485.c timer.c device.c
#common demo files needed
DEMOSRC = $(BACNET_DEMO)/handler/txbuf.c $(BACNET_DEMO)/handler/h_npdu.c $(BACNET_DEMO)/handler/s_iam.c $(BACNET_DEMO)/handler/noserv.c
# core BACnet stack files
CORESRC = $(BACNET_CORE)/crc.c $(BACNET_CORE)/npdu.c $(BACNET_CORE)/bacdcode.c $(BACNET_CORE)/bacint.c $(BACNET_CORE)/bacreal.c \
$(BACNET_CORE)/bacstr.c $(BACNET_CORE)/iam.c $(BACNET_CORE)/rp.c $(BACNET_CORE)/wp.c $(BACNET_CORE)/whois.c $(BACNET_CORE)/bacaddr.c \
$(BACNET_CORE)/abort.c $(BACNET_CORE)/reject.c $(BACNET_CORE)/bacerror.c $(BACNET_CORE)/bacapp.c
## Include Directories
INCLUDES = -I. -I$(BACNET_INCLUDE)
INCLUDES += -I$(BACNET_OBJECT)
INCLUDES += -I$(BACNET_HANDLER)
# Source to Object conversion
COBJ = $(CSRC:.c=.o)
DEMOOBJ = $(DEMOSRC:.c=.o)
COREOBJ = $(CORESRC:.c=.o)
OBJECTS = $(COBJ) $(DEMOOBJ) $(COREOBJ)
#Build and Link the objects
all: $(TARGET)
.c.o:
$(CC) -c $(INCLUDES) $(CFLAGS) $*.c -o $#
$(TARGET) : $(OBJECTS)
$(CC) $(CFLAGS) $(INCLUDES) $(OBJECTS) -o $(TARGET)
.PHONY: clean
clean:
$(RM) *.o *~ $(TARGET)
when issue make I get the .o files created and it does not creates an executable. I get the output as follows:
s_iam.c:(.text+0xed): undefined reference to `bip_get_my_address'
../../demo/handler/s_iam.o: In function `Send_I_Am_Unicast':
s_iam.c:(.text+0x16c): undefined reference to `bvlc_send_pdu'
../../demo/handler/noserv.o: In function `handler_unrecognized_service':
noserv.c:(.text+0x14): undefined reference to `bip_get_my_address'
noserv.c:(.text+0x6b): undefined reference to `bvlc_send_pdu'
../../src/bacapp.o: In function `bacapp_copy':
bacapp.c:(.text+0x7ac): undefined reference to `datetime_copy_date'
bacapp.c:(.text+0x7bb): undefined reference to `datetime_copy_time'
../../src/bacapp.o: In function `bacapp_snprintf_value':
bacapp.c:(.text+0xba4): undefined reference to `bactext_object_type_name'
bacapp.c:(.text+0xbbc): undefined reference to `bactext_event_state_name'
bacapp.c:(.text+0xbce): undefined reference to `bactext_engineering_unit_name'
bacapp.c:(.text+0xbe1): undefined reference to `bactext_binary_polarity_name'
bacapp.c:(.text+0xbf0): undefined reference to `bactext_binary_present_value_name'
bacapp.c:(.text+0xbfa): undefined reference to `bactext_reliability_name'
bacapp.c:(.text+0xc04): undefined reference to `bactext_device_status_name'
bacapp.c:(.text+0xc0e): undefined reference to `bactext_segmentation_name'
bacapp.c:(.text+0xc18): undefined reference to `bactext_node_type_name'
bacapp.c:(.text+0xc45): undefined reference to `bactext_day_of_week_name'
bacapp.c:(.text+0xc84): undefined reference to `bactext_month_name'
bacapp.c:(.text+0xe28): undefined reference to `bactext_object_type_name'
../../src/bacapp.o: In function `bacapp_parse_application_data':
bacapp.c:(.text+0x10bd): undefined reference to `datetime_set_date'
collect2: error: ld returned 1 exit status
make: *** [beaglebone] Error 1
Kindly tell me where I am going wrong and many thanks for your help and suggestions!!!
Regards,
Gibson
Looks like your object files are in a bit of a random order, so that later object files refer to symbol defined in earlier object files and this is why the link fails.
Try the following. Replace:
$(TARGET) : $(OBJECTS)
$(CC) $(CFLAGS) $(INCLUDES) $(OBJECTS) -o $(TARGET)
With:
$(TARGET) : $(OBJECTS)
$(CC) -o $# -Wl,--start-group $(OBJECTS) -Wl,--end-group
That is going to make ld to scan the object files for missing symbols a few times (like MSVC does).
here's my error
make
cc msgd.o -o msgd
msgd.o: In function `main':
/home/cam/Desktop/lab1/msgd.cc:37: undefined reference to `Server::Server(int, bool)'
/home/cam/Desktop/lab1/msgd.cc:39: undefined reference to `Server::~Server()'
msgd.o: In function `__static_initialization_and_destruction_0':
/usr/include/c++/4.7/iostream:75: undefined reference to `std::ios_base::Init::Init()'
/usr/include/c++/4.7/iostream:75: undefined reference to `std::ios_base::Init::~Init()'
msgd.o:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
make: *** [msgd] Error 1
The first two undefined references to Server:: are bogus, the code works and Server.h is included properly in msgd.cc.
However when I simply do "make server" it runs fine, and when I do "make client" it runs fine, but I want to be able to just do "make" and have it build both.
Here's my makefile. According to https://stackoverflow.com/a/10907227/2080104 I need to include -lstdcc++ but I can't seem to figure out how to do so in a makefile.
# Makefile for socket examples
CXX= g++ $(CCFLAGS)
msgd= msgd.o Server.o Data.o User.o Message.o Str.o
msg= msg.o Client.o Str.o
OBJS = $(msgd) $(msg)
CCFLAGS= -std=c++11 -g
all: msgd Server Data User Message Str msg Client
server:$(msgd)
$(CXX) -o msgd $(msgd)
client:$(msg)
$(CXX) -o msg $(msg)
clean:
rm -f $(OBJS) $(OBJS:.o=.d)
realclean:
rm -f $(OBJS) $(OBJS:.o=.d) msgd msg
# These lines ensure that dependencies are handled automatically.
%.d: %.cc
$(SHELL) -ec '$(CC) -M $(CPPFLAGS) $< \
| sed '\''s/\($*\)\.o[ :]*/\1.o $# : /g'\'' > $#; \
[ -s $# ] || rm -f $#'
include $(OBJS:.o=.d)
You named a variable msgd when you had an object file named msgd.o, and then you got them mixed up. Oh, and you have a target server which doesn't actually build server, it builds msgd.
You have a default target (all) which builds things other than what you want the default target to build.
You want to Make to do something (i.e. use -lstdcc++) when either you don't know how to do it on the command line, or you don't know which part of the makefile corresponds to what you do on the command line.
I'd suggest specific changes to the makefile, but your intent is so unclear I'm afraid I'd do more harm than good.
What happens is that target all requires msgd.
all: msgd Server Data User Message Str msg Client
You don't have a rule for msgd, however, make figures it can build msgd from msgd.o from msgd.cc (or whatever extension your source has) using the built-in rule:
Linking a single object file
n is made automatically from n.o by running the linker (usually called ld) via the C compiler. The precise recipe used is ‘$(CC) $(LDFLAGS) n.o $(LOADLIBES) $(LDLIBS)’.
Your makefile should look more like the following:
CXX := g++
CXXFLAGS := -std=c++11 -g
CPPFLGS :=
LDFLAGS :=
LDLIBS := -g
all : msgd msg
msgd_obj := msgd.o Server.o Data.o User.o Message.o Str.o
msg_obj := msg.o Client.o Str.o
OBJ := ${msgd_obj} ${msg_obj}
msgd : ${msgd_obj}
msg : ${msg_obj}
# The rule to link the executables.
msgd msg :
${CXX} -o $# ${LDFLAGS} $^ ${LDLIBS}
# The rule to compile object files and produce dependencies.
%.o : %.cc
${CXX} -o $# ${CPPFLAGS} ${CXXFLAGS} -MD -MP $<
clean:
rm -f $(OBJS) $(OBJS:.o=.d)
realclean:
rm -f $(OBJS) $(OBJS:.o=.d) msgd msg
-include $(OBJS:.o=.d)
.PHONY: all clean realclean
Note that there should not be a specific rule to produce dependencies. Dependencies are produced as a by-product of compilation. On the first run dependencies are unnecessary because everything must be built anyway, on subsequent runs it uses dependencies from the previous run to determine what have changed since.
This is a puzzle to me:
c++ undefined reference to destructor
That's the issue, the code is the same as the link, full makefile and errors here. The linked answers did help but only to highlight that I had some headers in a place I did not expect.
makefile
CXX = g++
BIN = .
LIBS = -L.
INCLUDE = -I . -I
CXXFLAGS = -pipe # -O6
LFLAGS = -lm
GeomTest_OBJS = geomTest.o SASAGeometry.o
geomTest_source = SASAGeometry.cpp SASAGeometry.h sasa_transformMatrix.cpp sasa_transformMatrix.h geomSetup.cpp
SASAGeometry.o : SASAGeometry.cpp SASAGeometry.h sasa_transformMatrix.cpp sasa_transformMatrix.h
geomTest.o : geomSetup.cpp
geomTest : $(GeomTest_OBJS) makefile
$(CXX) -o geomTest.o -o SASAGeometry.o $(LIBS) $(INCLUDE) $(CXXFLAGS) $(geomTest_source) $(LFLAGS)
$(CXX) $(LIBS) $(INCLUDE) $(CXXFLAGS) -o $(BIN)/geomTest geomTest.o SASAGeometry.o $(LFLAGS)
clean : \rm *.o *~ p1
I have both declared and instantiated the destructor AND not (allowing the compiler to do its thing)
error
geomSetup.cpp:(.text+0x5ab): undefined reference to `SASAGeometry::~SASAGeometry()'
geomSetup.cpp:(.text+0x5cd): undefined reference to `SASAGeometry::~SASAGeometry()'
no other errors. (sorry if its preferable to bump seemingly sorted issues rather than link to them, but my effort at that didn't work)
Thanks in advance!
EDIT:
MAKE SURE TO COMPILE THE CORRECT SOURCE FILES, NOT THE OLD ONES YOU FORGOT TO COPY.
Hi #trojanfoe and #Kerrick SB, both answers made me look at my makefile and realise it was ugly. Here is the revised version. I am still getting the same 'undefined reference to destructor' error though:
makefile:
CXX = g++
BIN = .
LIBS = -L.
INCLUDE = -I.
CXXFLAGS = -pipe # -O6
LDFLAGS = -lm
GeomTest_OBJS = sasa_transformMatrix.o SASAGeometry.o geomSetup.o
SASAGeometry.o : SASAGeometry.cpp SASAGeometry.h
sasa_transformMatrix.o : sasa_transformMatrix.cpp sasa_transformMatrix.h
geomSetup.o : geomSetup.cpp
geomTest : $(GeomTest_OBJS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $# $+
clean : \rm *.o *~ p1
error:
geomSetup.o: In function `main':
geomSetup.cpp:(.text+0x5ab): undefined reference to `SASAGeometry::~SASAGeometry()'
geomSetup.cpp:(.text+0x5cd): undefined reference to `SASAGeometry::~SASAGeometry()'
collect2: ld returned 1 exit status
make: *** [geomTest] Error 1
Why would the linker complain about the destructor and not the constructor or any other methods/functions in the class?
Thanks again!
Your executable output file and your object file geomTest.o have the same name! That's bound to get you into trouble when the linker overwrites the object file.
Change it to $(CXX) -o geomTest ..., or better even to $(CXX) $# ... to avoid such problems in the future.
In fact, you are misusing the linker command altogether: you just want to have one single -o option, and the objects are listed directly, without flags:
g++ -o myprog main.o foo.o bar.o
Within the Makefile, do yourself a favour and use magic macros:
myprog: main.o foo.o bar.o
$(CXX) $(LDFLAGS) -o $# $+ $(LIBRARIES)
Here -o $# matches the target name, i.e. -o myprog, and $+ matches all the dependent names, i.e. main.o foo.o bar.o.
The guiding idea behind using variables is that you should never say the same thing more than once if you can help it. So you can have myprog: $(MyObjects) as the rule, but then use $+ in the command line to avoid repetition of MyObjects. This improves locality and maintainability.
The -o SASAGeometry.o in the geomTest target looks highly suspect to me - you are overwriting one of the dependency objects (actually both dependencies).
Try this:
geomTest : $(GeomTest_OBJS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $# $(GemoTest_OBJS) $(LIBS)
(note that $LDFLAGS is the conventional variable in which to hold linker flags, not $LFLAGS which is used with the lex tool).