linking functions

Hi, I wrote several functions under VisualC (easier for me to debug :unamused: ), which were in the same workspace. Now I have to use these functions under QNX, but I don’t know how to link them.When I call the main programm, it doesn’t recognize the functions. So is ther sthg such as a workspace in QNX or do I have to put all my functions in the same file (which would be very big and hard to debug).
thx

You can link them together with your main.c, or generate a library of your own.

Thank you.
I’m generating a library including the functions, but I have a pb whith one of them while creating the .o (qcc file.c -c newfile). After 20 minutes it failed printing “unknown error”. Can this come from the size of this function(970,586 bits) ? Because it is a function generated by mapple and I had no pb whith smaller similar functions.

Sounds like you are running of out memory. Try to remove the optimization flags on the cc/qcc command line you have them. If still fail, you will have to compile this file on another machine with more RAM, and then copy the .o file back to link it.

After having generated a library, I tried to run my program, but it didn’t work. The terminal display this kind of message :

In file included from /home/…/simulink/simu_test.c:3:
/home/…/simulink/lib/sans_saisie.lib:404:unknown escape squence ‘\P’
/home/…/simulink/lib/sans_saisie.lib:416:stray ‘’ in program
/home/…/simulink/lib/sans_saisie.lib:421:nondigits in numbers and not hexadecimal

etc…

To create the library, I first created .o files by typing “qcc name_of_file.c -c name_of_file” and added it in the lybrary file by typing “ar -r name_of_archive.lib name_of_file.o”

and I wrote in my program "#include “name_of_archive.lib”

What do I do wrong ?

Assuming u have files like this: functions.h, functions.c, program.c and you want to create library from functions.* and executable from program.c

Compile C source file: “qcc -c functions.c -o functions.o” which will create object file named functions.o

Compile C source file which will be included in a shared library: “qcc -shared -c functions.c -o functions.o”

Create static library from functions.h and functions.c: “qcc -A libfunctions.a functions.o” which will create library file named libfunctions.a

Create shared library: “qcc -shared -o libfunctions.so functions.o” where functions.o must have been created using -shared

Ok, now u have static library libfunctions.a and/or shared library libfunctions.so

To include a static/shared library in a program put following in your program.c: “#include “functions.h”” which will allow to compile a program which uses library ‘functions’

Compile a program: “qcc -c program.c -o program.o”

Link (create final executable) program_static (using static library): “qcc -o program_static program.o -Bstatic -L ./ -l functions” which will create executable file ‘program_static’

Link program (using shared library): “qcc -shared -o program -L ./ -l functions” which will create executable file ‘program’ and this program will need ‘libfunctions.so’ to be able to run

Thanks to mezek, I have been able to link all my functions and to compile the code to create an executable which worked under QNX 6.1. But I changed for QNX 6.2.1. I have things to modify in my code, so I have to do these operations again. But even whith the same code and doing exactly the same operations, the executable I get does not have the same size as the previous one. And when I try to run it, I get a “memory fault (core dumped)”, because of dynamic allocation for arrays. If I set the allocation that cause the error as a comment, I get the same error one step further, which means it is not an error in the code. The memory bar in the menu indicates only 26%, even when I try to run the executable. So does anybody has an idea? Thank you.
guillaume

There is probably error in the code earlier, which is causing “memory fault”. It is possible that the error didnt show up in 6.1, but as of changes in 6.2.1 it came up …

Try to debug it and add more checks for library/system calls return values