chesterpolo / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

"make linux" fails because of misplaced -ldl option #207

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Clone the latest development version (currently it is on changeset 
126:8e51a29c2af6)
2. Type "make linux", enter.

What is the expected output?
Compiled binaries, both library and executable file.

What do you see instead?
Library compiles ok, when compiling an executable I get:

cc -ldl -pthread -W -Wall -std=c99 -pedantic -O2  mongoose.c main.c -o mongoose
/tmp/.private/odyssey/ccwJbBvT.o: In function `load_dll':
mongoose.c:(.text+0x110b): undefined reference to `dlopen'
mongoose.c:(.text+0x1123): undefined reference to `dlsym'
collect2: ld returned 1 exit status
make: *** [linux] Error 1

Please provide any additional information below.

It seems the linking fails because of misplaced -ldl option.
After the following replacement in makefile:
-   $(CC) $(LINFLAGS) mongoose.c main.c -o $(PROG)
+   $(CC) $(LINFLAGS) mongoose.c main.c -ldl -o $(PROG)
the build process succeeds.

According to GCC manual 
(http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html#Link-Options) -ldl option 
placement does matter. I would suggest removing -ldl from LINFLAGS and adding 
it to the command line as shown above.

Original issue reported on code.google.com by vvzh.dev@gmail.com on 28 Nov 2010 at 10:30

GoogleCodeExporter commented 9 years ago
This is weird. What Linux do you run, and what is the compiler version?

Original comment by valenok on 29 Nov 2010 at 11:59

GoogleCodeExporter commented 9 years ago
I use Simply Linux (a distribution based on ALT Linux)
"gcc --version" output is the following:
i586-alt-linux-gcc (GCC) 4.4.1 20090725 (ALT Linux 4.4.1-alt3)

Original comment by vvzh.dev@gmail.com on 29 Nov 2010 at 12:54

GoogleCodeExporter commented 9 years ago
It looks like "cc" command does something weird on your distribution.
It does not behave like it needs to.

Original comment by valenok on 30 Nov 2010 at 3:35

GoogleCodeExporter commented 9 years ago
I asked about this in mailing lists of my distribution and got an answer. In 
short, ALT Linux and Gentoo have -Wl,--as-needed option turned on by default, 
that leads to this behavior. The answer also says that -ldl should always be 
specified after .c and .o files because otherwise static building becomes 
broken in all distributions.

If you're interested, here is the link to the mailing-list discussion (in 
Russian):
http://lists.altlinux.org/pipermail/community/2010-December/667932.html

Original comment by vvzh.dev@gmail.com on 1 Dec 2010 at 8:19

GoogleCodeExporter commented 9 years ago
Ясно :-)
Submitted 
http://code.google.com/p/mongoose/source/detail?r=89a4380d90748699cd69e3361afe46
b16b4ee6a5

Thanks.

Original comment by valenok on 1 Dec 2010 at 9:26

GoogleCodeExporter commented 9 years ago
Спасибо :)

Original comment by vvzh.dev@gmail.com on 1 Dec 2010 at 7:00