LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 12-01-2014, 09:08 PM   #1
MarkWyz
LQ Newbie
 
Registered: Jan 2014
Location: Phoenix, AZ
Distribution: Ubuntu
Posts: 16

Rep: Reputation: Disabled
I want to write a C program that draws lines on the screen with Ubuntu 14.04


I have a Turbo C program that I want to port to gcc in Ubuntu 14.04.1. The program draws lines on the screen in graphics mode. I quickly found that gcc has no graphics.h. Some searching suggested that I wanted sdl.

I found libsdl-gfx1.2 in the Ubuntu software center and installed it. The documentation package came with sample programs including TestGfxPrimitives.c that among other things draws lines. I thought a good first step would be compiling the test program.

After fixing some include problems, the only error left (and there are several instaces of it) was "undefined reference". I'm guessing that this is because I haven't specified the sdl library using the -L parameter. Trouble is, I have no idea where this library is or what it is called.

Could someone tell me if my assumptions are correct and possibly what the library is called? Or am I going about this all wrong? Thanks for your time.
 
Old 12-02-2014, 04:51 AM   #2
manu-tm
Member
 
Registered: May 2008
Location: France
Distribution: Ubuntu, Debian
Posts: 343

Rep: Reputation: 43
To use SDL, you can compile with `sdl-config --cflags --libs`.
Can you provide what you typed exactly?
Also, "undefined reference" to what?

Last edited by manu-tm; 12-02-2014 at 04:54 AM.
 
1 members found this post helpful.
Old 12-02-2014, 04:58 AM   #3
qlue
Member
 
Registered: Aug 2009
Location: Umzinto, South Africa
Distribution: Crunchbangified Debian 8 (Jessie)
Posts: 747
Blog Entries: 1

Rep: Reputation: 172Reputation: 172
I'm not certain, having never coded in C before, but I'd guess that you need to install the libsdl-gfx1.2-dev package to use it in your own code.
Debian, Ubuntu and several other distros separate the development headers and they must be downloaded explicitly.

Please ignore this if you've already got the dev package.
 
1 members found this post helpful.
Old 12-02-2014, 05:41 PM   #4
MarkWyz
LQ Newbie
 
Registered: Jan 2014
Location: Phoenix, AZ
Distribution: Ubuntu
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by manu-tm View Post
To use SDL, you can compile with `sdl-config --cflags --libs`.
Can you provide what you typed exactly?
Also, "undefined reference" to what?
I typed 'gcc -o tgp TestGfxPrimitives.c'
There were dozens of undefined references, some of them were: SDL_Init, SDL_Quit, SDL_GetError, SDL_Delay, and lineRGBA.
I don't understand 'sdl-config --cflags --libs' is that a stand-alone command to be run, or does it go in the gcc command somewhere?
 
Old 12-02-2014, 05:53 PM   #5
MarkWyz
LQ Newbie
 
Registered: Jan 2014
Location: Phoenix, AZ
Distribution: Ubuntu
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by qlue View Post
I'm not certain, having never coded in C before, but I'd guess that you need to install the libsdl-gfx1.2-dev package to use it in your own code.
Debian, Ubuntu and several other distros separate the development headers and they must be downloaded explicitly.

Please ignore this if you've already got the dev package.
According to the ubuntu software center I have libsdl-gfx1.2-dev but not libsdl-gfx1.2-dev:i386. Do I need the second one?
I think I have all the header files. I think I'm missing (or can't find) the library.
 
Old 12-02-2014, 07:07 PM   #6
manu-tm
Member
 
Registered: May 2008
Location: France
Distribution: Ubuntu, Debian
Posts: 343

Rep: Reputation: 43
Quote:
Originally Posted by MarkWyz View Post
I typed 'gcc -o tgp TestGfxPrimitives.c'
There were dozens of undefined references, some of them were: SDL_Init, SDL_Quit, SDL_GetError, SDL_Delay, and lineRGBA.
I don't understand 'sdl-config --cflags --libs' is that a stand-alone command to be run, or does it go in the gcc command somewhere?
You must type:
gcc -o tgp TestGfxPrimitives.c `sdl-config --cflags --libs`

` is a backtick, not a quotation sign. `sdl-config --cflags --libs` is the same as $(sdl-config --cflags --libs), ie it will be replaced by the output of the command.

This will allow gcc to find the header files and libs needed to compile and link with SDL.

Maybe you will also need to add -lSDL_gfx or something similar.

Last edited by manu-tm; 12-02-2014 at 07:16 PM.
 
1 members found this post helpful.
Old 12-02-2014, 09:59 PM   #7
MarkWyz
LQ Newbie
 
Registered: Jan 2014
Location: Phoenix, AZ
Distribution: Ubuntu
Posts: 16

Original Poster
Rep: Reputation: Disabled
Progress! When I type
gcc -o tgp TestGfxPrimitives.c `sdl-config --cflags --libs`
I get only 330 lines of error ouput compared to 500 lines before. Adding -lSDL_gfx changes nothing. All of the undefined references to things that start with SDL_ are gone. But lineRGBA, stringRGBA, and many others are still there. Anyone have any ideas?
 
Old 12-03-2014, 02:39 AM   #8
manu-tm
Member
 
Registered: May 2008
Location: France
Distribution: Ubuntu, Debian
Posts: 343

Rep: Reputation: 43
gcc -o tgp TestGfxPrimitives.c `sdl-config --cflags --libs` -lSDL_gfx

(see above)
 
1 members found this post helpful.
Old 12-03-2014, 05:35 PM   #9
MarkWyz
LQ Newbie
 
Registered: Jan 2014
Location: Phoenix, AZ
Distribution: Ubuntu
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by manu-tm View Post
gcc -o tgp TestGfxPrimitives.c `sdl-config --cflags --libs` -lSDL_gfx
Success!!

Apparently the placement of -lSDL_gfx is important. I had placed it earlier in the command line with no luck. If anyone wants to explain why it needs to be at the end (or maybe just after the sdl-config) I'd love to hear it, but I'm going to mark this thread solved. Thanks manu-tm for your time and help.

Now for the work of porting my program.
 
Old 12-04-2014, 03:13 AM   #10
manu-tm
Member
 
Registered: May 2008
Location: France
Distribution: Ubuntu, Debian
Posts: 343

Rep: Reputation: 43
No prob

About the placement, not totally sure but it could be so because libsdl-gfx refers to functions in libsdl, so libsdl must be loaded before libsdl-gfx. I think it's somewhere in the gcc man page, but it's a long reading.
 
Old 12-06-2014, 12:26 AM   #11
MarkWyz
LQ Newbie
 
Registered: Jan 2014
Location: Phoenix, AZ
Distribution: Ubuntu
Posts: 16

Original Poster
Rep: Reputation: Disabled
I've ported my program and it works. Now I'm trying to cross compile it for Windows. I installed i586-mingw32msvc-gcc. I typed :

i586-mingw32msvc-gcc -Wall -o test test.c `sdl-config --cflags --libs` -lSDL_gfx -lm

I received the following errors:

In file included from /usr/include/SDL/SDL_main.h:26,
from /usr/include/SDL/SDL.h:30,
from test.c:16:
/usr/include/SDL/SDL_stdinc.h:74:20: error: iconv.h: No such file or directory
/usr/include/SDL/SDL_stdinc.h:187:22: error: alloca.h: No such file or directory
In file included from /usr/include/SDL/SDL_main.h:26,
from /usr/include/SDL/SDL.h:30,
from test.c:16:
/usr/include/SDL/SDL_stdinc.h:605: error: expected ‘)’ before ‘cd’

I found iconv.h and alloca.h in /usr/include. I tried adding -I/usr/include but that made the errors worse. Any ideas?
 
Old 12-11-2014, 03:43 AM   #12
Subhraman Sarkar
Member
 
Registered: Nov 2014
Distribution: Ubuntu 20.04 Focal Fossa
Posts: 60

Rep: Reputation: Disabled
Lightbulb

I am not a C programmer, but you may try adding symbolic links for iconv.h and alloca.h in the /usr/include/SDL directory with sudo nautilus or any other equivalent command in the terminal.
 
Old 12-12-2014, 02:16 AM   #13
manu-tm
Member
 
Registered: May 2008
Location: France
Distribution: Ubuntu, Debian
Posts: 343

Rep: Reputation: 43
I've only used MinGW on windows but you could check out http://mxe.cc/.
 
1 members found this post helpful.
Old 12-12-2014, 04:48 PM   #14
MarkWyz
LQ Newbie
 
Registered: Jan 2014
Location: Phoenix, AZ
Distribution: Ubuntu
Posts: 16

Original Poster
Rep: Reputation: Disabled
I've looked into this a little more and it seems it's terribly complex. I briefly looked at mxe.cc. Can I follow the Debian instructions for Ubuntu?

Using apt-get would be a first for me. I've only used the Ubuntu Software Center to install things. But I guess there's a first time for everything. Thanks for the pointer.
 
Old 12-12-2014, 06:06 PM   #15
manu-tm
Member
 
Registered: May 2008
Location: France
Distribution: Ubuntu, Debian
Posts: 343

Rep: Reputation: 43
Quote:
Originally Posted by MarkWyz View Post
Can I follow the Debian instructions for Ubuntu?
I think so but, as I told you, I've never used mxe, so...

About apt-get, it's not difficult and it's much faster than the ubuntu software center.
 
1 members found this post helpful.
  


Reply



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
[SOLVED] Ubuntu 14.04 lts - screen breaks up with horizontal lines, coloured rectangles ...... david k Ubuntu 5 10-13-2014 05:32 PM
what is the best graphics card for ubuntu 14.04 that draws under 90w? OldNoob Linux - Hardware 8 09-21-2014 03:45 PM
Bash: Is there a builtin command to write lines? stf92 Programming 22 07-26-2012 12:24 PM
ubuntu,Netbeans 7.0 ,Glassfish 3.1 Runtime exec C++ program does not write a file. Johannes Marx Programming 6 11-27-2011 09:26 PM
kpdf draws diagonal lines siarul Linux - Software 2 11-08-2007 01:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 08:02 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration