Linking Issues

Hi,

I am having a lot of troubles getting a shared object file to link with an existing program. The program had been previously created in PhAB, and has PhAB’s makefile structure.

I have created a library called liblasag.so and placed it in the /lib/dll directory (which is registered in the LD_LIBRARY_PATH variable). The library’s header file is also included in the correct places in the program.

Now I have tried to modify the Makefile in the program’s /src/gcc_ntox86 directory, but without much success. I have added -llasag, -l /lib/dll/liblasag.so and other variants (capital L etc) both infront of and behind the object files in the linking command. I think I have tried all the possible combinations, but I am not sure. If someone could let me in on the magic secret that’d be great.

Thanks

What error did you get?

try this -L/lib/dll -llasag

or maybe it’s an issue with incompatiblity between C and C++? You used things like

#ifdef  __cplusplus
extern "C" {
#endif

Hi,

The error is: undefined reference to ‘function’. It occurs once for each place a library function is called.

I do have files with exactly what you have above:
#ifdef __cplusplus
extern “C” {
#endif

They occur in files that typically start with dmc… (such as dmcisa, dmcint, dmcsup etc - I don’t know what they all do as this is someone elses program, although im pretty sure they are libraries for a pci card that is used).

However, when I tried to comment out these sections, it gave me even more errors for other functions that are in the dmcisa files. I’m not too sure what the __cplusplus means, is this something I can easily get rid of (and how), or do I have to find other non C++ versions of this library.

Thanks,
Brent

The -L/lib/dll -llasag command still generates an “undefined reference”. I have looked at the other files that have the __cplusplus argument and they compile in a version of the code that doesn’t use the library I am trying to add, and when I add the library, nothing in those files with the __cplusplus arguments change. If anyone has any suggestions that would be great - thanks

Well, you shouldn’t be putting the file in /lib/dll if it is a library. You should also be giving the shlib a soname (liblasag.so.1). Could you post the output from the link stage so we can see the exact errors you are getting?

The file is a shared object which I understood to be synonomous with a dynamically linked library, is that correct?

Momentics generates two files for the library - liblasag.so, and liblasag.so.1 - what is the .1 for, and when should I use that??

This is the linking command and its errors:

QCC abmain.o motionControl.o terminalCommand.o  motionMiscFunctions.o motionFunctions.o  -Vgcc_ntox86          -g -l phexlib -l Ap -l ph -l phrender -L /lib/dll -llasag -l m -l/opt/galil/dmcqnx.lib  -M -o terminalGalil

/root/tUW3/src/gcc_ntox86/../motionMiscFunctions.c:120: undefined reference to `laser_open_shutter(void)'
/root/tUW3/src/gcc_ntox86/../motionMiscFunctions.c:123: undefined reference to `laser_close_shutter(void)'
motionMiscFunctions.o: In function `motion_follow_path(void)':
/root/tUW3/src/gcc_ntox86/../motionMiscFunctions.c:147: undefined reference to `laser_initialize_comm(void)'
/root/tUW3/src/gcc_ntox86/../motionMiscFunctions.c:206: undefined reference to `laser_terminate_comm(void)'

Thanks

try to re-arrange the order of the libs. I normally put my own libs before the system libs.
I suspect your “dmcqnx.lib” uses lasag lib. try to move -llasag AFTER the -l/opt/galil/dmcqnx.lib

Rearranging the order like you said doesn’t work. The dmcqnx.lib does not use lasag, since dmcqnx.lib were provided by the hardware vendor and liblasag.so is something I developed myself for another piece of hardware entirely.

-Now this program was originally developed in a free version of qnx using PhAB, however I am now adding the liblasag.so library in the latest version, 6.2.1b - are there any compatibility issues there?

Thanks

I saw your link command uses QCC so I assume you are dealing with C++. I vaguely remember PhAB has issues with C++ (or does it support C++?). Hope cdm or others can give more information.