LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Issue creating dynamic libraries (https://www.linuxquestions.org/questions/programming-9/issue-creating-dynamic-libraries-4175455719/)

ams_pedro 03-26-2013 08:25 PM

Issue creating dynamic libraries
 
Hello,

I am developing an evolutionary program which needs to test a specific program many times, under different configurations.
I decided to use dynamic linking in order to speed up the testing process and up to this point everything was ok.

I used a script to run make and generate the new library, which was then included in the main program in order to be tested.
In a previous version this seemed to work just fine.

However, I had to perform a few changes so that the main program was executed in a process, and another program would load the linked dynamic library (used sockets to perform Inter Process Communication).

The thing is, strangely, after sometime, around 1000 recompilations of the dynamic library, it fails, saying the following:

gcc -c -m64 -O -Wall -fPIC -c -I /usr/local/include -Os DFuncDarwin.c
gcc -o pizza DFuncDarwin.o Misc.o --trace --shared -Wl,--dynamic-linker=/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 -o dfuncDarwin.so.1.0 -lm
/usr/bin/ld: cannot find /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
collect2: ld returned 1 exit status

make: *** [pizza] Error 1
BEGINING GEN 3 DUDE 95

I have no Idea why does this happen... and I could not find any answer. It works for so many cases, and then it fails...

Does any body has a clue about this ???

I would really appreciate...

I can improve the description if needed...

Thanks

dwhitney67 03-27-2013 04:15 AM

Perhaps you are attempting to build on a system where the file '/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2' does not exist. For example, I have that file under Kubuntu 12.04, but not under Fedora 16. A strong hint is:
Code:

/usr/bin/ld: cannot find /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
Frankly, I've never seen the option -Wl,dynamic-linker used. Can you elaborate as to why you think it is necessary to use this option to build your dynamic library?

pan64 03-27-2013 04:39 AM

I do not understand why do you have two -o <something> options, and why didn't you try -ldl instead of -Wl,--dynamic-linker=/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2. Also -I /usr/local/include is usually not required.

ams_pedro 03-27-2013 06:37 PM

The thing is, I do call the script that compiles the dynamic library around 1000 times, in runtime. But then it suddenly fails to find the file that it has used up until then. So the file must be there, but something is preventing to use it after some time ...

Well pan64, I guess you are right, I built that over some old code, and it was working ok, so I just letted it be.
I am going to remove the unnecessary -o <something>

The othe option:

-Wl,--dynamic-linker=/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2

I saw somewhere on the web that I thought it could help, but it didn't. I believe I am going to remove it.

I will clean it up...


I have tested it again, and a new error messages came out this time:

gcc -c -m64 -O -Wall -fPIC -c -I /usr/local/include -Os DFuncDarwin.c
gcc -o pizza DFuncDarwin.o --trace --shared -Wl,--dynamic-linker=/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 -o dfuncDarwin.so.1.0 -lm
BEGINING GEN 3 DUDE 101
echo> 1 3 101 0.001233FITNESS VALUE : 0.001233
TERMINATING GEN 3 DUDE 101
gcc -c -m64 -O -Wall -fPIC -c -I /usr/local/include -Os DFuncDarwin.c
gcc -o pizza DFuncDarwin.o --trace --shared -Wl,--dynamic-linker=/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 -o dfuncDarwin.so.1.0 -lm
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find /usr/lib/gcc/x86_64-linux-gnu/4.4.6/crtendS.o: Too many open files
/usr/bin/ld: cannot find /usr/lib/gcc/x86_64-linux-gnu/4.4.6/../../../x86_64-linux-gnu/crtn.o: Too many open files
collect2: ld returned 1 exit status
make: *** [pizza] Error 1
BEGINING GEN 3 DUDE 102
Server closed connection

With this new information I was able to find the cause for the error.

I was using UNIX sockets to perform Inter process comunication. In the server I was not adeuately closing the socket that was receiving the client's connection. As it ran too many times, it reached the limmit of FDs. Then, when trying to recompile the Dynamic library, it simply failed because it could not open more FDs.

So there was a leack.

Solved


All times are GMT -5. The time now is 11:42 PM.