compiling a C code

hello, I’m a newbie (I started to work under QNX a week ago), so sorry if my question seems stupid :blush:.

I have been given a code made by another student so it is supposed to work. In the terminal, I type : gcc name_of_folder.c -o new_folder.exe

The system seems to recognize the headers as I don’t have any error message for this. But I’ve a whole page of (for exemple):
/tmp/cc7bnv0t.o: In function ‘tran_inv’:
/tmp/cc7bnv0t.o(.text+0x8185): undefined reference to ‘atan2’
/tmp/cc7bnv0t.o(.text+0x81d2): undefined reference to ‘_Sin’
/tmp/cc7bnv0t.o(.text+0x8292): undefined reference to ‘sqrt’

Should I type others command to make the programm work ?
Can I find all these kinds of information somewhere ?
Thank you

Sounds like you are not linking against the math library.


qcc name_of_file.c -o new_file -lm

There is no need for a .exe extension under QNX, as the executable attribute is part of the files directory entry.

You may also want to ensure that the dir your maths lib is in, is included in the LD_LIBRARY_PATH environment variable.

with your information, I’m now linking against the math library, but not against the others libraries. So I guess “-lm” refers to math.h, but how can I know the links to the other ones ? Or is there another mean to manage ?
Moreover, what is the difference between qcc and gcc ?

how can I access LD_LIBRARY_PATH ?

Thank you you two for your answers (and your patience :laughing: )

Once the code can run, I would like to have it run via PhAB. I read the tutorial about the callbacks. So do I only have to click on “view → callbacks → Arm → Code” then to enter a name, to edit this code and replace it by the previous code to make it work ? Or am I far from reality :unamused: ?

qcc is the compiler that comes with QNX, gcc is the GNU compiler, to be honest I don’t know which is better optimised for QNX/intel.

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

will add /usr/local/lib to the LD_LIBRARY_PATH, you can do this before you compile, if it solves the problem, then you can put it in your bash profile, or whatever shell you use.

I think the math lib will be in /lib, which will probably already be in the LD_LIBRARY_PATH, so try compiling with the -lm flag, it might just work.

Not that far from reality ;-) You can put any C you like into a PhAB project, so you should be able to attach it to a button (which I assume is what you want to do) via the way you described. The only thing you might run into is that if your program takes arguments from the command line, which would not likely not be present in a GUI app.

Hope that helps.


cc, qcc and gcc are both front-end the the 2.7.2 (?) GNU compiler. There is only one compiler. Each front-end have different default option. I’m always confuse which to use when. I thing qcc is best ;-)

Huh, shows what I know…

i find that exposing one’s knowledge subject it to correction from other, a good thing in my opinion, check my post about PCI bandwidth ;-)

Heh… cc is mandated by the posix standard, qcc is QNX’s idea to provide a common front end for all their compilers (QNX4, QNX6, etc) and gcc is well, gcc. :slight_smile: The version of gcc currently available on QNX6.2.1 is 2.95.3. With the release of QNX6.3.0, you will have a choice of 2.95.3 or 3.3.1. The default will be 2.95.3.

Although you can usually get away with using gcc instead of qcc if you are using C code, it is much more problematic with C++ code. qcc is also much better suited for cross developing in QNX (compiling for arm, mips, sh, etc) on x86.

So, the best approach if you are starting from scratch is to use qcc. If you are taking existing *nix source and using configure, the best way to start it is:

CC=qcc CXX=QCC ./configure

Other info that is important is if you use floating point math, you generally need to link with a ‘-lm’ and if you use any tcp functions, you need to link with a ‘-lsocket’. Unlike many *nix varieties, all the pthread functions are built into libc, so you don’t need to link with ‘-lpthread’ (in fact it doesn’t exist).

Hmm… this was going to be a quick reply to correct Mario, since he brought up the whole correction thing. Obviously I am rambling this morning. :slight_smile:

thank you all for your explanations, but… :cry: it still doesn’t work.

I add the dir where the .h are to the LD_LIBRARY_PATH.But it doesn’t change anything when I try to compile it.
When I add the flag -lm after the command (qcc name_of_file.c -o new_file -lm), the math lib is indeed linked against my programm.But the problem remains for the other libraries. For exemple :

undefined reference to ‘textprintf’
undefined reference to ‘clear_bitmap’
undefined reference to ‘clear_zbuffer’
undefined reference to ‘gfx_driver’
undefined reference to ‘screen’set_projection_viewport’
undefined reference to ‘vsync’
undefined reference to ‘remove_mouse’
undefined reference to ‘screen’
undefined reference to ‘blit’
undefined reference to ‘show_mouse’
undefined reference to ‘install_allegro’
undefined reference to ‘apply_matrix_f’
undefined reference to ‘set_gfx_mode’

etc… which don’t depend on math.h.
So if you have any other suggestion :neutral_face:

Looks like it cannot find more libraries, a lot of those functions seems to be from Allegro and Sarien (both a sourceforge), so you’ve either not got the library (unlikely if you do have the header files), so it’s probably another LD_LIBRARY_PATH one, see what directories they are installed in and add them in the same way you did with the math lib.



Hi, I am new to QNX environment as with guillaume. I faced the same problem with <math.h>. The solution provided so far are command lines in the terminal. If I am using the IDE, how should I go about linking the library? Please advice, thank you.


Add a -lm to the end of your linker command line.

I’m sorry but how do I locate the linker command line in the IDE?

I don’t want to sound rude or anything but isn’t that a case of RTFM

Come on Mario - you know IDE’s are so easy to use that they don’t supply manuals.