Overview
Features
Download
Documentation
Community
Add-Ons & Services

HELP,For compile poco first program in Linux

A general discussion forum.

HELP,For compile poco first program in Linux

Postby wfdada » 19 May 2009, 09:25

I according to web : http://pocoproject.org/wiki/index.php/FirstStepsLinux
to build my first poco c++ program,
and I copy DateTimeSample.cpp to my Fedora 10 platform.
and copy Makefile :

include $(POCO_BASE)/build/rules/global # global rules: will find libs and include files for us
objects = DateTimeSample
target = DateTime
target_version = 1
target_libs = PocoFoundation
include $(POCO_BASE)/build/rules/exec #tells the Makefile we want to build an executable

,
system info :
Linux localhost.localdomain 2.6.27.5-117.fc10.x86_64 #1 SMP Tue Nov 18 11:58:53 EST 2008 x86_64 x86_64 x86_64 GNU/Linux

but it report ERROR:
/home/talent/work/POCO_TEST//obj/Linux/x86_64/debug_static/DateTimeSample.o: In function `main':
/home/talent/work/POCO_TEST/src/DateTimeSample.cpp:11: multiple definition of `main'
/home/talent/work/POCO_TEST//obj/Linux/x86_64/release_shared/DateTimeSample.o:DateTimeSample.cpp:(.text+0x0): first defined here
/home/talent/work/POCO_TEST//obj/Linux/x86_64/release_static/DateTimeSample.o: In function `main':
DateTimeSample.cpp:(.text+0x0): multiple definition of `main'
/home/talent/work/POCO_TEST//obj/Linux/x86_64/release_shared/DateTimeSample.o:DateTimeSample.cpp:(.text+0x0): first defined here
/home/talent/work/POCO_TEST//obj/Linux/x86_64/debug_shared/DateTimeSample.o: In function `main':
/home/talent/work/POCO_TEST/src/DateTimeSample.cpp:11: multiple definition of `main'
/home/talent/work/POCO_TEST//obj/Linux/x86_64/release_shared/DateTimeSample.o:DateTimeSample.cpp:(.text+0x0): first defined here
collect2: ld returned 1 exit status
make: *** [/home/talent/work/POCO_TEST//bin/Linux/x86_64/DateTimeMy] ERROR 1

So I don't know how to eliminate these errors.
Please Help me!
wfdada
 
Posts: 12
Joined: 19 May 2009, 09:15

Re: HELP,For compile poco first program in Linux

Postby aderouineau » 19 May 2009, 20:30

The problem seems to be that the compiler is seeing multiple main methods...

Can you try to compile the sample without using the makefile? (basically through the gcc command line directly)
aderouineau
 
Posts: 163
Joined: 18 May 2009, 17:38

Re: HELP,For compile poco first program in Linux

Postby wfdada » 20 May 2009, 04:51

Thank you for upstair's reply.
Yes,the Makefile generate those code:
g++ -DPOCO_BUILD_HOST=localhost.localdomain -D_XOPEN_SOURCE=500 -D_REENTRANT -D_THREAD_SAFE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -O2 -Wl,-rpath,/home/talent/work/POCO_TEST/lib/Linux/x86_64 -o /home/talent/work/POCO_TEST//bin/Linux/x86_64/DateTimeMy /home/talent/work/POCO_TEST//obj/Linux/x86_64/release_shared/DateTimeSample.o /home/talent/work/POCO_TEST//obj/Linux/x86_64/debug_static/DateTimeSample.o /home/talent/work/POCO_TEST//obj/Linux/x86_64/release_static/DateTimeSample.o /home/talent/work/POCO_TEST//obj/Linux/x86_64/debug_shared/DateTimeSample.o -L/home/talent/work/POCO_TEST/lib/Linux/x86_64 -L/home/talent/work/poco-1.3.5-all/lib/Linux/x86_64 -lPocoFoundation -lpthread -ldl -lrt

and it dosn't woek correct.
/home/talent/work/POCO_TEST//obj/Linux/x86_64/release_shared/DateTimeSample.o
/home/talent/work/POCO_TEST//obj/Linux/x86_64/debug_static/DateTimeSample.o
/home/talent/work/POCO_TEST//obj/Linux/x86_64/release_static/DateTimeSample.o
/home/talent/work/POCO_TEST//obj/Linux/x86_64/debug_shared/DateTimeSample.o
these four are compiled together,and report : multiple definition of `main'

So ,I only remain one : /home/talent/work/POCO_TEST//obj/Linux/x86_64/debug_static/DateTimeSample.o:
g++ -DPOCO_BUILD_HOST=localhost.localdomain -D_XOPEN_SOURCE=500 -D_REENTRANT -D_THREAD_SAFE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -O2 -Wl,-rpath,/home/talent/work/POCO_TEST/lib/Linux/x86_64 -o /home/talent/work/POCO_TEST//bin/Linux/x86_64/DateTimeMy /home/talent/work/POCO_TEST//obj/Linux/x86_64/debug_static/DateTimeSample.o -L/home/talent/work/POCO_TEST/lib/Linux/x86_64 -L/home/talent/work/poco-1.3.5-all/lib/Linux/x86_64 -lPocoFoundation -lpthread -ldl -lrt

It works correct.

so, it is the problem of Makefile ,and I don't known how to altered.
please , Help me.

PS:How to compile static lib .a file in linux with POCO makefile style? I have succes in windows .
wfdada
 
Posts: 12
Joined: 19 May 2009, 09:15

Re: HELP,For compile poco first program in Linux

Postby aderouineau » 20 May 2009, 11:13

It might be a problem with the makefile; did you try building another sample? Or building this one on another computer?
(I don't have a computer right now to test myself)

Try building like this:
1) Go in the folder with the cpp file
2) Type in: g++ -o DateTimeSample DateTime.cpp -lPocoFoundation -static

That's assuming you installed the library on the system. If you only built it in a folder, you'll have to specify the locations of the headers and the built Foundation library.
aderouineau
 
Posts: 163
Joined: 18 May 2009, 17:38

Re: HELP,For compile poco first program in Linux

Postby guenter » 20 May 2009, 11:46

I have experienced this problem once as well. Unfortunately, I don't remember the exact cause. Try removing the .dep, obj and bin directories and rewrite the Makefile from scratch (by copying the Makefile from the sample). It is most probably an issue with the Makefile. Also, make sure that both POCO_BASE and PROJECT_BASE environment vars are set correctly.

If your project hierarchy looks like this:
Code: Select all
work
    poco/
        Foundation/
            include/
        ...
    POCO_TEST

src/

then POCO_BASE must be /home/talent/work/poco and PROJECT_BASE must be /home/talent/work
guenter
 
Posts: 1135
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: HELP,For compile poco first program in Linux

Postby aderouineau » 20 May 2009, 12:37

Wouldn't it be easier just to run the g++ command manually? Redoing the makefile is just a pain in the arse.

Another option for simplified compiling/linking is scons. Might be slower than the other projects, but it's very easy to use.
aderouineau
 
Posts: 163
Joined: 18 May 2009, 17:38

Re: HELP,For compile poco first program in Linux

Postby wfdada » 21 May 2009, 04:30

Thank you for guenter and aderouineau .
My problem solved,and really the issue of Makefile and PROJECT_BASE environment .

first,I try g++ -o DateTimeSample DateTime.cpp -lPocoFoundation -static , It works OK.

then,I am set PROJECT_BASE environment correctly,and copy Makefile from samples clearly,
this time ,make makefile compiled succeed.

using the POCO Makefile style is simple and clear.

Now ,I can start my Poco c++ lib both in windows and Linux.
Thank you!
wfdada
 
Posts: 12
Joined: 19 May 2009, 09:15

Re: HELP,For compile poco first program in Linux

Postby wfdada » 21 May 2009, 09:44

I am so stupid that the real reason of this problem is in Makefile:
include $(POCO_BASE)/build/rules/global # global rules: will find libs and include files for us
objects = DateTimeSample
target = DateTime
target_version = 1
target_libs = PocoFoundation
include $(POCO_BASE)/build/rules/exec #tells the Makefile we want to build an executable

there is a space letter after DateTime : "target = DateTime "
then ,it dosn't work correct.

to delete this space is OK.
wfdada
 
Posts: 12
Joined: 19 May 2009, 09:15

Re: HELP,For compile poco first program in Linux

Postby aderouineau » 21 May 2009, 13:07

So now it works?
aderouineau
 
Posts: 163
Joined: 18 May 2009, 17:38

Re: HELP,For compile poco first program in Linux

Postby wfdada » 21 May 2009, 14:49

aderouineau wrote:So now it works?


Yes!
excellent.
Thanks.
wfdada
 
Posts: 12
Joined: 19 May 2009, 09:15

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron