Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation process #2

Closed
DanielJean007 opened this issue Sep 24, 2019 · 5 comments · Fixed by #3
Closed

Installation process #2

DanielJean007 opened this issue Sep 24, 2019 · 5 comments · Fixed by #3

Comments

@DanielJean007
Copy link

Hi there, Thanks for the lib.

Could you , please, provide instruction for installing your lib.
I have tried with autoreconf --install, etc, but with no luck.

Thanks in advance.

@goeb
Copy link
Owner

goeb commented Sep 24, 2019

What goes wrong?
It is a standard autotools install process.

Typical installation on my computer:

$ git clone ~/reference/mq
$ cd mq
$ autoreconf --install
configure.ac:11: installing './compile'
configure.ac:8: installing './install-sh'
configure.ac:8: installing './missing'
src/Makefile.am: installing './depcomp'
$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
[...]
checking for strerror... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating config.h
config.status: executing depfiles commands
$ make 
make  all-recursive
Making all in src
gcc -DHAVE_CONFIG_H -I. -I..     -g -O2 -MT mq.o -MD -MP -MF .deps/mq.Tpo -c q.c
mv -f .deps/mq.Tpo .deps/mq.Po
gcc  -g -O2 -lrt  -o mq mq.o  
$ make install DESTDIR=/tmp/mq
Making install in src
 /bin/mkdir -p '/tmp/mq/usr/local/bin'
  /usr/bin/install -c mq '/tmp/mq/usr/local/bin'
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
$ find /tmp/mq
/tmp/mq
/tmp/mq/usr
/tmp/mq/usr/local
/tmp/mq/usr/local/bin
/tmp/mq/usr/local/bin/mq

@DanielJean007
Copy link
Author

DanielJean007 commented Sep 24, 2019

Hi Goeb, here's the problem.
When I make it, this shows up:

make  all-recursive
make[1]: Entering directory '/home/danieljean/Codes/Testes/S/mq-master'
Making all in src
make[2]: Entering directory '/home/danieljean/Codes/Testes/S/mq-master/src'
gcc -DHAVE_CONFIG_H -I. -I..     -g -O2 -MT mq.o -MD -MP -MF .deps/mq.Tpo -c -o mq.o mq.c
mq.c: In function ‘cmd_recv_follow’:
mq.c:352:6: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
      write(1, buffer, n);
      ^~~~~~~~~~~~~~~~~~~
mq.c:353:6: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
      write(1, &args->delimiter, 1); /* delimiter */
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mq.c: In function ‘cmd_recv’:
mq.c:305:3: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
   write(1, buffer, n);
   ^~~~~~~~~~~~~~~~~~~
mq.c:306:3: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
   write(1, &args->delimiter, 1);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mv -f .deps/mq.Tpo .deps/mq.Po
gcc  -g -O2 -lrt  -o mq mq.o  
mq.o: In function `mq_open':
/usr/include/x86_64-linux-gnu/bits/mqueue2.h:54: undefined reference to `__mq_open_2'
mq.o: In function `cmd_recv_follow':
/home/danieljean/Codes/Testes/S/mq-master/src/mq.c:329: undefined reference to `mq_getattr'
/home/danieljean/Codes/Testes/S/mq-master/src/mq.c:348: undefined reference to `mq_receive'
mq.o: In function `mq_open':
/usr/include/x86_64-linux-gnu/bits/mqueue2.h:50: undefined reference to `mq_open'
mq.o: In function `cmd_info':
/home/danieljean/Codes/Testes/S/mq-master/src/mq.c:217: undefined reference to `mq_getattr'
mq.o: In function `cmd_recv':
/home/danieljean/Codes/Testes/S/mq-master/src/mq.c:313: undefined reference to `mq_close'
mq.o: In function `mq_open':
/usr/include/x86_64-linux-gnu/bits/mqueue2.h:50: undefined reference to `mq_open'
mq.o: In function `cmd_recv':
/home/danieljean/Codes/Testes/S/mq-master/src/mq.c:295: undefined reference to `mq_close'
mq.o: In function `cmd_unlink':
/home/danieljean/Codes/Testes/S/mq-master/src/mq.c:233: undefined reference to `mq_unlink'
mq.o: In function `mq_open':
/usr/include/x86_64-linux-gnu/bits/mqueue2.h:54: undefined reference to `__mq_open_2'
mq.o: In function `cmd_send':
/home/danieljean/Codes/Testes/S/mq-master/src/mq.c:257: undefined reference to `mq_send'
mq.o: In function `cmd_recv':
/home/danieljean/Codes/Testes/S/mq-master/src/mq.c:293: undefined reference to `mq_getattr'
/home/danieljean/Codes/Testes/S/mq-master/src/mq.c:301: undefined reference to `mq_receive'
collect2: error: ld returned 1 exit status
Makefile:328: recipe for target 'mq' failed
make[2]: *** [mq] Error 1
make[2]: Leaving directory '/home/danieljean/Codes/Testes/S/mq-master/src'
Makefile:352: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/danieljean/Codes/Testes/S/mq-master'
Makefile:293: recipe for target 'all' failed
make: *** [all] Error 2

Here's my system (uname -a)
Linux PED-4243 5.0.0-29-generic #31~18.04.1-Ubuntu SMP Thu Sep 12 18:29:21 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Thanks in advance for any help.

@goeb
Copy link
Owner

goeb commented Sep 26, 2019

It looks like your librt does not have the mq_open symbol. I do not know why... In my Linux distribution (Debian), it is documented that the mq functions are in librt ("Link with -lrt").

What does "man mq_open" tell you?

You can also look at the lib directly:

readelf -a /usr/lib/.../x86_64-linux-gnu/librt.so | grep mq_open
       89: 0000000000004460    29 FUNC    GLOBAL DEFAULT   14 __mq_open_2@@GLIBC_2.7
      102: 00000000000043d0   140 FUNC    GLOBAL DEFAULT   14 mq_open@@GLIBC_2.3.4

If you miss the librt.so, then you need to install it (apt install libc6-dev).

@DanielJean007
Copy link
Author

It all checks out but still got the same error.

I will investigate further.

@rotty
Copy link
Contributor

rotty commented Oct 23, 2019

This is an issue with the Makefile.am, using AM_LDFLAGS to add libraries is not correct, you should use mq_LDADD instead.

Edit: It seems newer toolchains no longer resolve symbols when the library precedes the referencing object file. This has always been the case for static libraries, as far as I'm aware, but now seems to also be the case for shared libs. So the issue is that by using AM_LDFLAGS, you add -lrt to the beginning of the linker invocation, while it should go at the end. Using mq_LDADD instead moves the -lrt to right place.

rotty added a commit to rotty/mq that referenced this issue Oct 23, 2019
The `_LDFLAGS` family of variables is not appropriate for specifying
libraries to link against, since libraries are (potentially)
order-dependent. That is, symbols referenced by an object file will
only be resolved by libraries that are specified *after* the object
file.

This has always been the case for static libraries, but it seems newer
toolchains also enforce order for shared libraries; at least with GCC
9.2.1 and GNU ld 2.33.1, this lead the build failing at the linker
stage, as described in issue goeb#2.

Fixes: goeb#2.
@goeb goeb closed this as completed in #3 Oct 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants