Reputation: 180
I started a C project on my local Ubuntu machine. After I completed the first version(the building is ok), I decided to upload the code to a server which runs a CentOS 7 to implement more features.
The code and the makefiles are the same on both sides.
But the code building on the remote shows the error as follows:
/usr/bin/ld: cannot find -ldl
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
yum install glibc-devel
But it did not work. How should I fix this?
I found the makefile I wrote a week ago is a little bit strange on LDFLAGS,
LDFLAGS += -L$(LIBPATH)
LDFLAGS += -static -lxxx -lyyy -ldl
xxx and yyy is the static library name I need to link.
I modified the makefile to
LDFLAGS += -L$(LIBPATH)
LDFLAGS += -l:libxxx.a -l:libyyy.a -ldl
Now it works fine.
Upvotes: 1
Views: 2553
Reputation: 33747
-static
requires the glibc-static
package, not just glibc-devel
. But static linking has many limitations (particularly in combination with dlopen
), and you should avoid it if at all possible. (It is explicitly unsupported on Red Hat Enterprise Linux.)
Upvotes: 3