I am trying to compile a C program that requires the use of several libraries. The problem is, the order the libraries are linked in causes the compilation to fail.
Is there anyway to get GCC to figure out the correct order, or for me to figure out the correct order without having to try every possibility?
mipsel-linux-gcc ffmpeg_mips_test.c -o ffmpeg_mips_test -Wall -v -I/ffmpegMIPS/includeffmpegMIPS/
-L/ffmpegMIPS/libffmpegMIPS/ -lavformat -lavcodec -lavutil -lswscale -lm -lpthread
The way I am doing it at the moment, is starting off with one, and then adding more libraries as the errors occur, however sometimes it feels like progress and then sometimes it just seems like I hit a dead end.
[edit]The compilation fails because of undefined references[/edit]
You have a few options
1) You can add additional calls to your library(s) that have dependencies
2) You can use the --start-group / --end-group
options like so:
mipsel-linux-gcc ffmpeg_mips_test.c -o ffmpeg_mips_test -Wall -v -I/ffmpegMIPS/includeffmpegMIPS/
-L/ffmpegMIPS/libffmpegMIPS/ -Wl,--start-group -lavformat -lavcodec -lavutil -lswscale -Wl,--end-group -lm -lpthread
Here is the ld
manpage entry describing its use
The specified archives are searched repeatedly until no new undefined references are created. Normally, an archive is searched only once in the order that it is specified on the command line. If a symbol in that archive is needed to resolve an undefined symbol referred to by an object in an archive that appears later on the command line, the linker would not be able to resolve that reference. By grouping the archives, they all be searched repeatedly until all possible references are resolved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With