Weird error " multiple definition of `xxx` " while compiling C++ project - c++

When I try to compile my C++ project via my Makefile I keep getting errors like those:
Server.o: In function `Bot::getRandomMessage()':
/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:18: multiple definition of `Bot::getRandomMessage()'
Bot.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:18: first defined here
Server.o: In function `Bot':
/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:27: multiple definition of `Bot::Bot()'
Bot.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:27: first defined here
Server.o: In function `~Bot':
/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:30: multiple definition of `Bot::~Bot()'
Bot.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:30: first defined here
Server.o: In function `~Bot':
/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:30: multiple definition of `Bot::~Bot()'
Bot.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:30: first defined here
Server.o: In function `~Bot':
/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:30: multiple definition of `Bot::~Bot()'
Bot.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:30: first defined here
Server.o: In function `Bot::getName()':
/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:33: multiple definition of `Bot::getName()'
Bot.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:33: first defined here
Server.o: In function `ChatRoom::getCurrentTime()':
/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Server.cpp:74: multiple definition of `ChatRoom::getCurrentTime()'
main.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Server.cpp:74: first defined here
Server.o: In function `Bot::getRandomMessage()':
/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:18: multiple definition of `vectorOfThreads'
main.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Server.cpp:74: first defined here
Server.o: In function `Bot::getRandomMessage()':
I'm quite confused with that.. When I compile it directly with the command
g++ main.cpp -Wall -pedantic -Wno-long-long -O0 -ggdb -lncurses -pthread -o AppName , then it doesn't produce any error. So I expect, that the error appears somewhere in my Makefile
#macros
Remove=rm -rf
Doxygen=Doxyfile
RUN=./dvoram64
FLAGS=-Wall -pedantic -Wno-long-long -O0 -ggdb -pthread -lncurses -g
OBJECTS=main.o Bot.o Server.o Client.o GrumpyBot.o JokerBot.o WeatherBot.o DummyBot.o
#generates final binary and documentation
all: $(Doxygen)
make compile
#build into final binary
compile: $(RUN)
#run program
run:
make link
$(RUN)
$(RUN)
clean:
$(Remove) dvoram64
$(Remove) $(OBJECTS)
#generate documentation in '<login>/doc' folder
doc: $(Doxygen) /*
( cd ./ | doxygen $(Doxygen))
link: $(OBJECTS)
g++ $(OBJECTS) -lncurses -pthread -o dvoram64
#rules how to compile into the executalble file
$(RUN): $(OBJECTS)
Bot.o: ./Bot.cpp ./Bot.h
g++ $(FLAGS) -c ./Bot.cpp
DummyBot.o: ./DummyBot.cpp ./DummyBot.h ./Bot.h
g++ $(FLAGS) -c ./DummyBot.cpp
GrumpyBot.o: ./GrumpyBot.cpp ./GrumpyBot.h ./Bot.h
g++ $(FLAGS) -c ./GrumpyBot.cpp
JokerBot.o: ./JokerBot.cpp ./JokerBot.h ./Bot.h
g++ $(FLAGS) -c ./JokerBot.cpp
WeatherBot.o: ./WeatherBot.cpp ./WeatherBot.h ./Bot.h
g++ $(FLAGS) -c ./WeatherBot.cpp
Client.o: ./Client.cpp
g++ $(FLAGS) -c ./Client.cpp
main.o: ./main.cpp
g++ $(FLAGS) -c ./main.cpp
Server.o: ./Server.cpp ./Bot.h ./JokerBot.h ./WeatherBot.h ./GrumpyBot.h ./DummyBot.h
g++ $(FLAGS) -c ./Server.cpp
Could anybody please explain me, what causes this error and show me, how to fix it?

Look at what the error messages are telling you. Start with the first lines:
Server.o: In function `Bot::getRandomMessage()':
/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:18: multiple definition of `Bot::getRandomMessage()'
This message says that the object file Server.o contains a multiple definition of the function Bot::getRandomMessage() function, and that the multiple definition comes from line 18 in the source file Bot.cpp. Now look at the next line:
Bot.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:18: first defined here
This tells you that the definition in Server.o is a multiple definition because there is also a definition in Bot.o. It also tells you the definition in Bot.o came from line 18 in the source file Bot.cpp, which is the same place in the source as the other definition.
This means that Bot.cpp was compiled at least twice, once to make Server.o and once to make Bot.o.
That is probably not what you want. It suggests that some of your source or header files include Bot.cpp when you meant to include Bot.h, or that you have otherwise included Bot.cpp incorrectly. Another possibility is that you have a compile command that compiles Bot.cpp to make Server.o.

generally when i face something like this ...... its a double rule occurrence or the project environment is messed up but Bro , this ain't a makefile issue.
you will have to look into the code ..... I simulated and tested the makefile you put in the question here , with empty files and echo . The makefile seems to be working a-ok.
Kaizen ~/so_test $ make -nf mk.t2
make compile
Kaizen ~/so_test $ make -nf mk.t2 compile
echo g++ -Wall -pedantic -Wno-long-long -O0 -ggdb -pthread -lncurses -g -c ./main.cpp
echo g++ -Wall -pedantic -Wno-long-long -O0 -ggdb -pthread -lncurses -g -c ./Bot.cpp
echo g++ -Wall -pedantic -Wno-long-long -O0 -ggdb -pthread -lncurses -g -c ./Server.cpp
echo g++ -Wall -pedantic -Wno-long-long -O0 -ggdb -pthread -lncurses -g -c ./Client.cpp
echo g++ -Wall -pedantic -Wno-long-long -O0 -ggdb -pthread -lncurses -g -c ./GrumpyBot.cpp
echo g++ -Wall -pedantic -Wno-long-long -O0 -ggdb -pthread -lncurses -g -c ./JokerBot.cpp
echo g++ -Wall -pedantic -Wno-long-long -O0 -ggdb -pthread -lncurses -g -c ./WeatherBot.cpp
echo g++ -Wall -pedantic -Wno-long-long -O0 -ggdb -pthread -lncurses -g -c ./DummyBot.cpp
i cant deduce much of a suggestion based on whats there , srry ...

When you compile with g++ main.cpp -Wall -pedantic -Wno-long-long -O0 -ggdb -lncurses -pthread -o AppName you actually don't include your Server, Client, Bot, DummyBot etc. (That you have in your makefile). Thats why you don't see that error.
also If main.cpp compiles without any other files then why do you need these Client, Bot, Server etc .. in your makefile ?
There must be a redefinition somewhere. try to clean and recompile. and then check the functions that its reporting. like Server.cpp:74, Bot.cpp:18, Bot::getRandomMessage()
also surprisingly your main.cpp doesn't call any Server, Bot ... functions. If it calls its supposed to throw linker errors.

Related

make error: “g++: error: bin/main.o: No such file or directory”

I'm trying to compile a program I wrote, and the structure of the directory is the following:
ctrace > bin, include, src, makefile
bin>
include > Agent.h, Graph.h, Session.h, Tree.h
src> Agent.cpp, ContactTracer.cpp, Graph.cpp, main.cpp, Session.cpp, Tree.cpp, Virus.cpp
The error I'm getting is the following:
g++: error: bin/main.o: No such file or directory
Makefile:5: recipe for target 'cTrace' failed
make: *** [cTrace] Error 1
and this is my make file:
# All Targets
all: cTrace
cTrace: bin/Session.o bin/Agent.o bin/Graph.o bin/Tree.o bin/Virus.o bin/ContactTracer.o
#echo 'Building target: cTrace'
g++ bin/Session.o bin/Agent.o bin/Graph.o bin/Tree.o bin/Virus.o bin/ContactTracer.o bin/main.o -o cTrace
#echo 'target cTrace built successfully'
bin/main.o: src/main.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude -o bin/main.o src/main.cpp
bin/Session.o: src/Session.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude -o bin/Session.o src/Session.cpp
bin/Agent.o: src/Agent.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude src/Agent.cpp -o bin/Agent.o
bin/Graph.o: src/Graph.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude src/Graph.cpp -o bin/Graph.o
bin/Tree.o: src/Tree.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude src/Tree.cpp -o bin/Tree.o
bin/Virus.o: src/Virus.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude src/Virus.cpp -o bin/Virus.o
bin/ContactTracer.o: src/ContactTracer.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude src/ContactTracer.cpp -o bin/ContactTracer.o
clean:
rm -rf bin/*.o cTrace
What could be the issue? all directories exist, my guess is that main.o is never generated but I can't see why as I don't fully understand all the flags in the makefile. Any tips on how to write a better makefile would be appreciated.
On a side note, I was able to run this exact same project using a CMake generated by CLion.
Thanks in advance.
You are missing bin/main.o as dependency for cTrace target. That's why make does not compile it, and resulting object file is missing. Just add bin/main.o to your list of dependencies in line 4.
Problem seems to be that bin/main.o should be mentioned as a dependency of cTrace
cTrace: bin/Session.o bin/Agent.o bin/Graph.o bin/Tree.o bin/Virus.o bin/ContactTracer.o bin/main.o
At present building cTrace doesn't cause the make file to try and build bin/main.o and so you get an error about a missing file.

Running HTTP server example from Boost Asio

I'm getting errors when trying to run the HTTP server example that comes with the source of the boost library, under the path: boost_1_59_0/libs/asio/example/cpp11/http/server/.
I already ran this following commands in the boost_1_59_0 directory:
$ ./bootstrap.sh
$ sudo ./bjam install
$ sudo ./b2 install
After installing all targets, i tried to compile the main.cpp and the server.cpp with this command: g++ -std=c++0x -o main main.cpp -I "/home/user/Desktop/boost_1_59_0" -L "/home/user/Desktop/boost_1_59_0/libs/" -lboost_system.
Any suggestion on how to compile this server example?
I linked all files from the boost_1_59_0/libs/asio/example/cpp11/http/server/ folder after the main.cpp, as #Richard Hodges suggested. It still didn't work, i got errors concerning lpthread, so i added it to the compiling options. The program compiled but it failed the execution, returning an error saying that it didn't find the library libboost_system.so.1.59.0. I tried linking the folders with -L /path/to/library but it didn't work.
Solution:
My compilation command:
g++ -std=gnu++0x -o main main.cpp server.cpp connection.cpp connection_manager.cpp reply.cpp mime_types.cpp request_handler.cpp request_parser.cpp -I "/home/user/Desktop/boost_1_59_0" -lboost_system -lpthread
I solved it with this commands:
$ LD_LIBRARY_PATH="/usr/local/lib/"
$ sudo ldconfig
And then I just ran the executable and it worked!
Here's a simple makefile I just concocted that works:
all:server
CPPFLAGS+=-std=c++11 -Wall -pedantic
CPPFLAGS+=-g -O2
CPPFLAGS+=-pthread
LDFLAGS+=-lboost_system
%.o:%.cpp
$(CXX) $(CPPFLAGS) $^ -c -o $#
server:$(patsubst %.cpp,%.o,$(wildcard *.cpp))
$(CXX) $(CPPFLAGS) $^ -o $# $(LDFLAGS)
It runs make:
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread connection.cpp -c -o connection.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread connection_manager.cpp -c -o connection_manager.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread main.cpp -c -o main.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread mime_types.cpp -c -o mime_types.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread reply.cpp -c -o reply.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread request_handler.cpp -c -o request_handler.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread request_parser.cpp -c -o request_parser.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread server.cpp -c -o server.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread connection.o connection_manager.o main.o mime_types.o reply.o request_handler.o request_parser.o server.o -o server -lboost_system
And the test program runs:
$ ./server 0.0.0.0 9889 . &
$ GET http://localhost:9889/main.cpp > main.cpp.0
Check the files
$ md5sum main.cpp*
be5dc1c26b5942101a7895de6baedcee main.cpp
be5dc1c26b5942101a7895de6baedcee main.cpp.0
Don't forget to kill the server when you're done

Compiling code directly from .cpp files works. Making object files first and then linking, results in Multiple Definition of Function Error?

# Compiler
CXX := g++
CF := -g
# c files
CFILES := $(wildcard src/*.cpp)
SOURCES := $(CFILES) # $(CFILES2) all CFILES
# o files
OBJECTS := $(SOURCES:.cpp=.o)
OBJECTS_A:= $(SOURCES:.cpp=_a.o)
# Macros
MACRO = -D
INFO = -DINFO // optional
DCDREAD = -DDCDREAD
# More Macros
DEFAULT = -DDEFAULT
CONTACT = -DDEFAULT -DCONTACT -DCONTACTPERSIST -DTENSION_COSTHETA
MTCONTACT = -DDEFAULT -DMTCON1 -DMTCON2
DCDCON = -DDCDREAD -DCONTACT -DCONTACTPERSIST -DTENSION_COSTHETA
DCDMT = -DDCDREAD -DMTCON1 -DMTCON2
CENMOV = -DDCDREAD -DMTCON1 -DCENTROIDMOVEMENT
ANGLE = -DDCDREAD -DINERTIA -DANGLE
ANG3 = -DDCDREAD -DMTCON1 -DANGLE3CENTROID
ang3o: $(OBJECTS_A)
$(CXX) $(OBJECTS_A) -o test/$(EXEC)_dcd_angle3centroid
cd test && ./$(EXEC)_dcd_angle3centroid mtonly_seamup.ref.pdb mtonly_seamup_d1_indent.dcd 1 209 1
ang3: $(OBJECTS)
$(CXX) $(SOURCES) $(CF) $(INC) $(LIB) $(ANG3) -o test/$(EXEC)_dcd_angle3centroid
cd test && ./$(EXEC)_dcd_angle3centroid mtonly_seamup.ref.pdb mtonly_seamup_d1_indent.dcd 1 209 1
# To obtain object files
$(OBJECTS_A) : $(SOURCES)
$(CXX) $(CF) $(INC) $(LIB) $(ANG3) -c $< -o $#
%.o: %.cpp
$(CXX) $(CC_FLAGS) $(INC) $(LIB) -c $< -o $#
I know the objects are unnecessary in the ANG3 rule. The c files are compiled directly, the executable runs correctly! I'd like to switch to objects, an ANG3O rule. HERE is my main question, am I trying to link .o files incorrectly at the end of the ANG3O rule?
ANG3 works.
ANG3O fails. Multiple Definitions of Function Error.
make ang3
g++ -g -O3 -Iinclude -pthread -c src/readfile.cpp -o src/readfile.o
g++ -g -O3 -Iinclude -pthread -c src/main.cpp -o src/main.o
g++ -g -O3 -Iinclude -pthread -c src/md.cpp -o src/md.o
g++ -g -O3 -Iinclude -pthread -c src/chain.cpp -o src/chain.o
g++ src/readfile.cpp src/main.cpp src/md.cpp src/chain.cpp -g -Iinclude -pthread -DDCDREAD -DMTCON1 -DANGLE3CENTROID -o test/run_segment_dcd_angle3centroid
make ang3o
g++ -g -Iinclude -pthread -DDCDREAD -DMTCON1 -DANGLE3CENTROID -c src/readfile.cpp -o src/readfile_a.o
g++ -g -Iinclude -pthread -DDCDREAD -DMTCON1 -DANGLE3CENTROID -c src/readfile.cpp -o src/main_a.o
g++ -g -Iinclude -pthread -DDCDREAD -DMTCON1 -DANGLE3CENTROID -c src/readfile.cpp -o src/md_a.o
g++ -g -Iinclude -pthread -DDCDREAD -DMTCON1 -DANGLE3CENTROID -c src/readfile.cpp -o src/chain_a.o
g++ src/readfile_a.o src/main_a.o src/md_a.o src/chain_a.o -o test/run_segment_dcd_angle3centroid
src/main_a.o: In function `ReadLines(Chain*)':
/home/d/sop_dev/contacts/segment/src/readfile.cpp:43: multiple definition of `ReadLines(Chain*)'
src/readfile_a.o:/home/d/sop_dev/contacts/segment/src/readfile.cpp:43: first defined here
src/main_a.o: In function `ReadMolecularContent(char*)':
/home/d/sop_dev/contacts/segment/src/readfile.cpp:208: multiple definition of `ReadMolecularContent(char*)'
src/readfile_a.o:/home/d/sop_dev/contacts/segment/src/readfile.cpp:208: first defined here
src/md_a.o: In function `ReadLines(Chain*)':
/home/d/sop_dev/contacts/segment/src/readfile.cpp:43: multiple definition of `ReadLines(Chain*)'
src/readfile_a.o:/home/d/sop_dev/contacts/segment/src/readfile.cpp:43: first defined here
src/md_a.o: In function `ReadMolecularContent(char*)':
/home/d/sop_dev/contacts/segment/src/readfile.cpp:208: multiple definition of `ReadMolecularContent(char*)'
src/readfile_a.o:/home/d/sop_dev/contacts/segment/src/readfile.cpp:208: first defined here
src/chain_a.o: In function `ReadLines(Chain*)':
/home/d/sop_dev/contacts/segment/src/readfile.cpp:43: multiple definition of `ReadLines(Chain*)'
src/readfile_a.o:/home/d/sop_dev/contacts/segment/src/readfile.cpp:43: first defined here
src/chain_a.o: In function `ReadMolecularContent(char*)':
/home/d/sop_dev/contacts/segment/src/readfile.cpp:208: multiple definition of `ReadMolecularContent(char*)'
src/readfile_a.o:/home/d/sop_dev/contacts/segment/src/readfile.cpp:208: first defined here
/usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Makefile:172: recipe for target 'ang3o' failed
make: *** [ang3o] Error 1
NOTES:
Related question: Error with multiple definitions of function
Possibly related: One definition rule and different class definitions in two translation units
However, in my situation:
the headers are in the include directory. The c files are in a src directory. All functions are declared in the headers. Only headers are included, no c/cpp files. Makefile examples seem to halt just before this level of complexity, the use of different define segments of code, and the need to compile objects with/without certain defined sections.
It helps to actually read the output.
g++ -g -Iinclude -pthread -DDCDREAD -DMTCON1 -DANGLE3CENTROID -c src/readfile.cpp -o src/readfile_a.o
g++ -g -Iinclude -pthread -DDCDREAD -DMTCON1 -DANGLE3CENTROID -c src/readfile.cpp -o src/main_a.o
g++ -g -Iinclude -pthread -DDCDREAD -DMTCON1 -DANGLE3CENTROID -c src/readfile.cpp -o src/md_a.o
g++ -g -Iinclude -pthread -DDCDREAD -DMTCON1 -DANGLE3CENTROID -c src/readfile.cpp -o src/chain_a.o
You're compiling the same C++ source file over and over again, then linking it to itself.
Your mistake is in the recipe to build objects. I'll leave you to read the documentation and find out why.

Create a debug file when compiling each source file separately using makefile

I am doing a c++ project with multiple source files and trying to get used to using makefiles. I want to be able to debug this program with gdb. If I use the following command in Terminal to compile, it works fine:
g++ -o main -g *.cpp
But if I just call make it doesn't generate a debug file (the .dSYM file) even though it compiles the program fine. I assume this has something to do with creating the individual object files first. Here is my makefile:
all: main.o sort.o bubble.o quickSort.o rbs.o
g++ -g -o main *.o -Wall -O2
main.o: main.cpp
g++ -c main.cpp
sort.o: sort.cpp sort.h
g++ -c sort.cpp
bubble.o: bubble.cpp bubble.h
g++ -c bubble.cpp
quickSort.o: quickSort.cpp quickSort.h
g++ -c quickSort.cpp
rbs.o: rbs.cpp rbs.h
g++ -c rbs.cpp
clean:
rm *.o
How do I create the main.dSYM debug file when using a makefile like this?
If you want the debug files, you must compile all of the components with -g.
The crude way to do this would be to add -g to every object rule:
all: main.o sort.o bubble.o quickSort.o rbs.o
g++ -g -o main *.o -Wall -O2
main.o: main.cpp
g++ -c -g main.cpp
sort.o: sort.cpp sort.h
g++ -c -g sort.cpp
bubble.o: bubble.cpp bubble.h
g++ -c -g bubble.cpp
quickSort.o: quickSort.cpp quickSort.h
g++ -c -g quickSort.cpp
rbs.o: rbs.cpp rbs.h
g++ -c -g rbs.cpp
But that doesn't leave you the option of building without debug information. And there's a lot of redundancy in this makefile. Let's take this in stages. First, we put in automatic variables to simplify the rules:
all: main.o sort.o bubble.o quickSort.o rbs.o
g++ -g -o main $^ -Wall -O2
main.o: main.cpp
g++ -c -g $<
sort.o: sort.cpp sort.h
g++ -c -g $<
bubble.o: bubble.cpp bubble.h
g++ -c -g $<
quickSort.o: quickSort.cpp quickSort.h
g++ -c -g $<
rbs.o: rbs.cpp rbs.h
g++ -c -g $<
Now we see that all of the *.o rules have the same command, which reminds us that Make already knows how to build foo.o from foo.cpp, with a command that looks like:
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c
So all we have to do is add -g to CXXFLAGS, and we can omit the commands entirely:
CXXFLAGS += -g
all: main.o sort.o bubble.o quickSort.o rbs.o
g++ -g -o main $^ -Wall -O2
sort.o: sort.h
bubble.o: bubble.h
quickSort.o: quickSort.h
rbs.o: rbs.h
Now that that's in order, we can set up two top-level targets, main and debug, and change CXXFLAGS only for the latter:
debug: CXXFLAGS += -g
main debug: main.o sort.o bubble.o quickSort.o rbs.o
g++ -g -o $# $^ -Wall -O2
sort.o: sort.h
bubble.o: bubble.h
quickSort.o: quickSort.h
rbs.o: rbs.h
You can improve this even more, but that should get you started.

C++ linking error when linking postgresql

When compiling my code I run into an issue as follows:
io.cpp:21: undefined reference to `PQconnectdb'
as well as all other instances of missing postgres function calls occurring in my code. Obviously this is a linking problem, I'm just not sure what the link issue is.
I'm compiling with the following:
mpiCC -c -O2 -g -Wall -Werror -I /usr/include/postgresql/ decisioning_mpi.cpp
g++ -c -O2 -g -Wall -Werror -I /usr/include/postgresql/ io.cpp
g++ -c -O2 -g -Wall -Werror -I /usr/include/postgresql/ calculations.cpp
g++ -c -O2 -g -Wall -Werror -I /usr/include/postgresql/ rules.cpp
g++ -c -O2 -g -Wall -Werror -I /usr/include/postgresql/ Instrument.cpp
g++ -c -O2 -g -Wall -Werror -I /usr/include/postgresql/ Backtest_Parameter_CPO.cpp
g++ -c -O2 -g -Wall -Werror -I /usr/include/postgresql/ Backtest_Trade_CPO.cpp
g++ -c -O2 -g -Wall -Werror -I /usr/include/postgresql/ Data_Bar.cpp
mpiCC -o decisioning_mpi -O2 -g -Wall -Werror -L/usr/lib -lm -lpq decisioning_mpi.o
io.o calculations.o rules.o Instrument.o Backtest_Parameter_CPO.o Backtest_Trade_CPO.o Data_Bar.o
It should be noted that this is the correct directory for libpq-fe.h and that I'm linking pq, so I'm not exactly sure why the postgres functions aren't linking correctly. I'm running Ubuntu 12.04 and installed psql (PostgreSQL) 9.1.6 from synaptic. As well I'll short circuit this, I am using #include "libpq-fe.h".
Any ideas on how I can get this linking issue resolved?
put -L/usr/lib/ -lm -lpq in the end of link command, the linker can then find the symbols
mpiCC -o decisioning_mpi -O2 -g -Wall -Werror decisioning_mpi.o io.o \
calculations.o rules.o Instrument.o Backtest_Parameter_CPO.o \
Backtest_Trade_CPO.o Data_Bar.o -L/usr/lib -lm -lpq
GCC Link Reference:
http://www.network-theory.co.uk/docs/gccintro/gccintro_18.html