LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-22-2011, 12:24 PM   #1
fedoraDrew
LQ Newbie
 
Registered: Oct 2008
Posts: 10

Rep: Reputation: 0
SDL + Eclipse + CDT hello world compiling but not linking with g++ on arch linux


Hi all,

I have set up Eclipse + CDT on an Arch 2010.05 install. I set up an eclipse project and added SDL as a dependency (see below):

Project -> Properties
* -> GCC C++ Compiler -> Preprocessor -> main=SDL_main
* -> GCC C++ Linker -> Libraries -> SDLmain SDL (in that order top to bottom)
* -> GCC C++ Linker -> Libraries -> Library Search Path -> /usr/lib/ (I verified that libSDL.a and libSDLmain.a are there)

This is the code I'm compiling. It's designed to just be a hello world style SDL app to see that everything is working.
Code:
#include <SDL/SDL.h>

int main(int argc, char **argv)
{
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Quit();
    return 0;
}
But when I compile I get this error:
Code:
Building target: client
Invoking: GCC C++ Linker
g++ -L/usr/lib/ -o"client"  ./src/engine/CEngine.o ./src/engine/main.o   -lSDLmain -lSDL
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.5.2/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [client] Error 1
Anyone know how to set up Eclipse + CDT + SDL properly?
 
Old 01-22-2011, 12:34 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Q: Does "./src/engine/main.o" exist?

Q: Is "main.cpp" the file you posted above (with "int main()" in it)?
 
Old 01-22-2011, 05:45 PM   #3
fedoraDrew
LQ Newbie
 
Registered: Oct 2008
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by paulsm4 View Post
Q: Does "./src/engine/main.o" exist?
Yes it does. I found it in the Debug/src/engine/ directory where the compiler spits out all its output. Eclipse also sets a default behavior to cd to the Debug/ dir when running the executable.

Quote:
Originally Posted by paulsm4 View Post
Q: Is "main.cpp" the file you posted above (with "int main()" in it)?
Yes, the code pasted above is contained in that file. There are some other files that get compiled too (the /src/engine/CEngine bit) but I am not using them yet.
 
Old 01-22-2011, 06:25 PM   #4
fedoraDrew
LQ Newbie
 
Registered: Oct 2008
Posts: 10

Original Poster
Rep: Reputation: 0
If I remove the symbol mapping of main to SDL_main (i.e. do NOT pass the argument -Dmain=SDL_main) then there is no compilation or link problem and the program runs as expected.

I'm not sure why all the tutorials I've read say to set SDL_main, but since I can compile and run now, I'm marking this as resolved.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Metrics plug-in for Eclipse, does it support Eclipse CDT? like2learn Programming 2 04-02-2012 03:13 AM
[SOLVED] make SDL fails on Arch Linux fedoraDrew Programming 1 01-22-2011 12:26 PM
Eclipse-CDT allows C/C++ landonmkelsey Linux - Software 1 11-24-2010 12:24 PM
Eclipse CDT mlpa Slackware 4 09-13-2010 10:20 AM
Eclipse : installing CDT vmelkon Ubuntu 1 08-02-2007 10:01 PM


All times are GMT -5. The time now is 07:05 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration