Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Linker problem under linux

Hello,
 
I've been posting questions on this board a few times now regarding linking applications with nidaqmxbase. As i've understood
nidaqmxbase spawns a couple of threads and executes my application in one of those threads.  my application uses the nilibs together with glib-2.0. When i compile my application  using standard linux development tools like autoconf, automake, libtool etc, i get the strangest error message.
The compliation looks like this and is autogenerated by configure script:
 
if gcc -DHAVE_CONFIG_H -I. -I. -I..    -I/opt/gnome/include/glib-2.0 -I/opt/gnome/lib/glib-2.0/include    -g -O2 -MT nid-counter.o -MD -MP -MF ".deps/nid-counter.Tpo" -c -o nid-counter.o `test -f 'counter.c' || echo './'`counter.c; \
then mv -f ".deps/nid-counter.Tpo" ".deps/nid-counter.Po"; else rm -f ".deps/nid-counter.Tpo"; exit 1; fi
if gcc -DHAVE_CONFIG_H -I. -I. -I..    -I/opt/gnome/include/glib-2.0 -I/opt/gnome/lib/glib-2.0/include    -g -O2 -MT nid-dio.o -MD -MP -MF ".deps/nid-dio.Tpo" -c -o nid-dio.o `test -f 'dio.c' || echo './'`dio.c; \
then mv -f ".deps/nid-dio.Tpo" ".deps/nid-dio.Po"; else rm -f ".deps/nid-dio.Tpo"; exit 1; fi
if gcc -DHAVE_CONFIG_H -I. -I. -I..    -I/opt/gnome/include/glib-2.0 -I/opt/gnome/lib/glib-2.0/include    -g -O2 -MT nid-nid.o -MD -MP -MF ".deps/nid-nid.Tpo" -c -o nid-nid.o `test -f 'nid.c' || echo './'`nid.c; \
then mv -f ".deps/nid-nid.Tpo" ".deps/nid-nid.Po"; else rm -f ".deps/nid-nid.Tpo"; exit 1; fi
if gcc -DHAVE_CONFIG_H -I. -I. -I..    -I/opt/gnome/include/glib-2.0 -I/opt/gnome/lib/glib-2.0/include    -g -O2 -MT nid-input.o -MD -MP -MF ".deps/nid-input.Tpo" -c -o nid-input.o `test -f 'input.c' || echo './'`input.c; \
then mv -f ".deps/nid-input.Tpo" ".deps/nid-input.Po"; else rm -f ".deps/nid-input.Tpo"; exit 1; fi
gcc  -g -O2   -o nid -lnidaqmxbase -lnidaqmxbaselv -L/opt/gnome/lib -lglib-2.0    nid-counter.o nid-dio.o nid-nid.o nid-input.o
As you can see the linking occurs on the last line. If i run the application i get the following output:
 ./nid
Unable to open X display.
Error initializing LabVIEW shared library (error 1)
This is a very strange message since i dont use any X routines in my application. Is there any linkage to X libraries in nidaqmxbase ?
 
If i run ldd on the libnidaqmxbase.so
./ldd libnidaqmxbase.so.1
        linux-gate.so.1 =>  (0xffffe000)
        libnidaqmxbaselv.so => /usr/local/lib/libnidaqmxbaselv.so (0x40022000)
        liblvrt.so => /usr/local/lib/liblvrt.so (0x4002b000)
        libc.so.6 => /lib/tls/libc.so.6 (0x40745000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)
        libLVMesaGL.so.3 => /usr/local/lib/libLVMesaGL.so.3 (0x4085b000)
        libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x40940000)
        libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x40a3c000)
        libm.so.6 => /lib/tls/libm.so.6 (0x40a4b000)
        libdl.so.2 => /lib/libdl.so.2 (0x40a6e000)
        libpthread.so.0 => /lib/tls/libpthread.so.0 (0x40a72000)
It clearly shows that X is linked in. Another strange thing is when i compile it manually with the following line:
gcc -I. -I/opt/gnome/include/glib-2.0 -I/opt/gnome/lib/glib-2.0/include -O2 nid.c dio.c input.c counter.c -lnidaqmxbase -lnidaqmxbaselv -llvrtdark -L/opt/gnome/lib -lglib-2.0 -o nid
 
Then the application runs.  Does anyone know what might cause this strange phenomenon ?
I must say that nidaqmxbase is a very very buggy library. I suggest NI start using libtool when making libraries in the future.
 
cheers
/Josef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0 Kudos
Message 1 of 5
(4,275 Views)
Josef,

This isn't strange, or buggy behavior.  In the first case you are linking against liblvrt.so (The LabVIEW Runtime Engine).  The LabVIEW Runtime Engine requires X.  In the second case that worked you Linked against llvrtdark (The LabVIEW Runtime Engine that doesn't require X).  So what you experienced is expected behavior.  If you are writing DAQmx Base applications that don't require X then you can and should link against llvrtdark.

Shawn B.
National Instruments
Use NI products on Linux? Come join the NI Linux Users Community
0 Kudos
Message 2 of 5
(4,270 Views)

Hello Shawn,

Ýou where right about the library. However another error appears when i use the correct library. When i compile with the following lines:

if gcc -DHAVE_CONFIG_H -I. -I. -I..    -I/opt/gnome/include/glib-2.0 -I/opt/gnome/lib/glib-2.0/include   -Wall -g -O2 -MT nid-counter.o -MD -MP -MF ".deps/nid-counter.Tpo" -c -o nid-counter.o `test -f 'counter.c' || echo './'`counter.c; \
then mv -f ".deps/nid-counter.Tpo" ".deps/nid-counter.Po"; else rm -f ".deps/nid-counter.Tpo"; exit 1; fi
if gcc -DHAVE_CONFIG_H -I. -I. -I..    -I/opt/gnome/include/glib-2.0 -I/opt/gnome/lib/glib-2.0/include   -Wall -g -O2 -MT nid-dio.o -MD -MP -MF ".deps/nid-dio.Tpo" -c -o nid-dio.o `test -f 'dio.c' || echo './'`dio.c; \
then mv -f ".deps/nid-dio.Tpo" ".deps/nid-dio.Po"; else rm -f ".deps/nid-dio.Tpo"; exit 1; fi
if gcc -DHAVE_CONFIG_H -I. -I. -I..    -I/opt/gnome/include/glib-2.0 -I/opt/gnome/lib/glib-2.0/include   -Wall -g -O2 -MT nid-nid.o -MD -MP -MF ".deps/nid-nid.Tpo" -c -o nid-nid.o `test -f 'nid.c' || echo './'`nid.c; \
then mv -f ".deps/nid-nid.Tpo" ".deps/nid-nid.Po"; else rm -f ".deps/nid-nid.Tpo"; exit 1; fi
if gcc -DHAVE_CONFIG_H -I. -I. -I..    -I/opt/gnome/include/glib-2.0 -I/opt/gnome/lib/glib-2.0/include   -Wall -g -O2 -MT nid-input.o -MD -MP -MF ".deps/nid-input.Tpo" -c -o nid-input.o `test -f 'input.c' || echo './'`input.c; \
then mv -f ".deps/nid-input.Tpo" ".deps/nid-input.Po"; else rm -f ".deps/nid-input.Tpo"; exit 1; fi
/bin/sh ../libtool --mode=link --tag=CC gcc  -g -O2   -o nid -L/opt/gnome/lib -lglib-2.0    nid-counter.o nid-dio.o nid-nid.o nid-input.o  -llvrtdark -lnidaqmxbase
mkdir .libs
gcc -g -O2 -o nid nid-counter.o nid-dio.o nid-nid.o nid-input.o  -L/opt/gnome/lib /opt/gnome/lib/libglib-2.0.so -llvrtdark -lnidaqmxbase

I get this error when trying to execute the application

./nid
ERROR! The LabVIEW RunTime Engine failed to initialize correctly.
This is usually caused by linking applications incorrectly.
Please see the AppLibs/README.shlibs file in the LabVIEW directory for
instructions on building programs using LabVIEW-built shared libraries.


LabVIEW caught fatal signal
 - Received SIGSEGV
Reason: address not mapped to object
Attempt to reference address: 0x4
Segmentation fault

When i run

gdb ./nid

I get the following;

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1090661296 (LWP 27212)]
0x401f3c22 in GenericListInternals<unsigned char const*>::NumElts () from /usr/local/lib/liblvrtdark.so.7.0
(gdb)

Is there a known bug in liblvrtdark.so.7.0 ?

As before. The application runs fine if i compile at the prompt with:

gcc -I. -I/opt/gnome/include/glib-2.0 -I/opt/gnome/lib/glib-2.0/include -O2 nid.c dio.c input.c counter.c -lnidaqmxbase -lnidaqmxbaselv -llvrtdark -L/opt/gnome/lib -lglib-2.0 -o nid

I would appreciate an answer..

 

Cheers /Josef

 

 

 


 

 

0 Kudos
Message 3 of 5
(4,266 Views)

Hello again.

I think i've found the bug.

If i link the application with the follwing:

 

gcc -g -O2 -o nid nid-counter.o nid-dio.o nid-nid.o nid-input.o -llvrtdark -lnidaqmxbase -lnidaqmxbaselv  -L/opt/gnome/lib /opt/gnome/lib/libglib-2.0.so

I get

./nid
ERROR! The LabVIEW RunTime Engine failed to initialize correctly.
This is usually caused by linking applications incorrectly.
Please see the AppLibs/README.shlibs file in the LabVIEW directory for
instructions on building programs using LabVIEW-built shared libraries.


LabVIEW caught fatal signal
 - Received SIGSEGV
Reason: address not mapped to object
Attempt to reference address: 0x4
Segmentation fault

But if i link it with:

gcc -g -O2 -o nid nid-counter.o nid-dio.o nid-nid.o nid-input.o -lnidaqmxbase -lnidaqmxbaselv -llvrtdark  -L/opt/gnome/lib /opt/gnome/lib/libglib-2.0.so

Then It runs fine.

The following also works:

gcc -g -O2 -o nid nid-counter.o nid-dio.o nid-nid.o nid-input.o -L/opt/gnome/lib /opt/gnome/lib/libglib-2.0.so -lnidaqmxbase -lnidaqmxbaselv -llvrtdark

 gcc -g -O2 -o nid nid-counter.o nid-dio.o nid-nid.o nid-input.o -L/opt/gnome/lib /opt/gnome/lib/libglib-2.0.so -lnidaqmxbaselv -llvrtdark  -lnidaqmxbase

But not:

gcc -g -O2 -o nid nid-counter.o nid-dio.o nid-nid.o nid-input.o -L/opt/gnome/lib /opt/gnome/lib/libglib-2.0.so -lnidaqmxbase -llvrtdark  -lnidaqmxbaselv

It seems that one must link in -lnidaqmxbaselv before -llvrtdark.

It also works when im not using X.

The conclusion is that everyone who wants to develop under linux beware of how you link your application to ni library.

Why havent this feature been well documented by NI. I know that NI have written one page about linking problem but it was hard getting that

document and it didnt contain that much, mostly about problems under Solaris and not under Linux.

 

 

 /josef

 

 

 


 

 

 

0 Kudos
Message 4 of 5
(4,265 Views)

For the record.

If anyone except me is using autoconf and automake together with nilibs one must add the libraries in the following order in configure.in

AC_CHECK_LIB(lvrtdark,main,,AC_MSG_ERROR(nid needs lvrtdark))
AC_CHECK_LIB(nidaqmxbaselv, main,, AC_MSG_ERROR(nid needs nidaqmxbaselv))
AC_CHECK_LIB(nidaqmxbase,DAQmxBaseStartTask,, AC_MSG_ERROR(nid needs nidaqmxbase))

Cheers /josef

 

0 Kudos
Message 5 of 5
(4,263 Views)