I had been working on a project that uses different sources and codes from many authors (in physics) and I want to merge them together and communicate between them. The problem is that some of those sources and makefiles call first the linked libraries and then the c files:
$(CC) $(lflags) -o smith2demo smith2demo.o smith2.o
Until now on my institute's computer and in some other systems everything was working fine. There I have this gcc compiler:
$gcc --version
gcc (Debian 4.9.2-10) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
So, I had not noticed this problem until I tried to run my code on Ubuntu:
gcc (Ubuntu 4.9.3-5ubuntu1) 4.9.3
Copyright (C) 2015 Free Software Foundation, Inc.
In ubuntu I get things like:
smith2.c:(.text+0x29b): undefined reference to `sincos'
I am aware of the linked libraries specifications and the reason for this, answered here:
Why does the order in which libraries are linked sometimes cause errors in GCC?
Why am I getting a gcc "undefined reference" error trying to create shared objects?
So, I have two questions:
Why if both gcc's are of recent versions, I do not have this problem in the Debian system?
How can I do to distribute this code to other people, without me telling them to change all makefiles where the libraries are called before the C files?
In most of the cases within my project, I use an overall Makefile and then I just change to the source folder and perform $(MAKE)
in there.
Is there a way to set the --no-as-needed
in general as an option for everyone or a more intelligent way of doing this?
I have very little experience with makefiles.