[SOLVED] I want to write a C program that draws lines on the screen with Ubuntu 14.04
UbuntuThis forum is for the discussion of Ubuntu Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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?
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.
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.
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?
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.
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.
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?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.