Where is libavformat for FFMpeg located on Snow Leopard? - makefile

Having an issue with getting a makefile to find the correct libraries and header files for a .c program I'm trying to compile. I'm trying to compile an open source segmenter for Apple's HTTP Live Streaming and it requires libavformat and other FFMpeg libraries to compile. I used Mac Ports to install FFMpeg and when I run "which ffmpeg" at command line, the directory it shows is opt/local/bin/ffmpeg, but after searching around, this doesn't seem to be the directory with the libraries.
It seems that the libraries are located in opt/local/include because that is where I see the header files. Here is my makefile with the suspected directory:
all:
gcc -Wall -g live_segmenter.c -o live_segmenter -I/opt/local/include -I/opt/local/bin -I/opt/local/include/libavutil -L/opt/local/include/libavformat -libavformat -L/opt/local/include -libavcodec -L/opt/local/include -libavutil -L/opt/local/include -libavcore -lbz2 -lm -lz -lfaac -lmp3lame -lx264 -lfaad -lpthread
clean:
rm -f live_segmenter
And here is the output after trying to compile:
gcc -Wall -g live_segmenter.c -o live_segmenter -I/opt/local/include -I/opt/local/bin -
I/opt/local/include/libavutil -L/opt/local/include/libavformat -libavformat -L/opt/local/include -libavcodec -L/opt/local/include -libavutil -L/opt/local/include -libavcore -lbz2 -lm -lz -lfaac -lmp3lame -lx264 -lfaad -lpthread
ld: library not found for -libavformat
collect2: ld returned 1 exit status
make: *** [all] Error 1
I also tried running "ffmpeg -version" to see if ffmpeg was built correctly and it seems to be so I have run out of ideas on what to do. Any help or point in the right direction would be great. Thank you!

I think you have too many -I and not enough -L. From gcc(1) on Lion:
-I dir
Add the directory dir to the list of directories to be searched for
header files. Directories named by -I are searched before the standard
system include directories. If the directory dir is a standard system
include directory, the option is ignored to ensure that the default
search order for system directories and the special treatment of system
headers are not defeated.
-L dir
Add directory dir to the list of directories to be searched for -l.
-l<libname> is a linker directive that tells ld to include lib<libname> from wherever in the -L directory list.
Try this, instead:
gcc -Wall -g live_segmenter.c -o live_segmenter -I/opt/local/include -L/opt/local/lib -lavcodec -lavutil -lavcore -lbz2 -lm -lz -lfaac -lmp3lame -lx264 -lfaad -lpthread

Related

I cannot compile when I use the flag -fast

I am compiling using this command:
icc -O3 MD.c util.c control.c -o MD
and it works fine, but I want to use also the flag -fast
I compile like that:
icc -O3 -fast MD.c util.c control.c -o MD
and I receive the this message:
ld: cannot find -lm
ld: cannot find -lc
ld: cannot find -ldl
ld: cannot find -lc
Do I need to include any library?
P.S.: I am using the compiler
intel-cc-17/17.0.2.174
I think I found the why it doesn't compile.
The command is -Ofast. I used -Ofast and it works fine!
I usually find it in literature as -fast, that's why I used this command initially

How to convert assembly code to executable in LLVM

I have converted c program into assembly code using following commands in LLVM :
clang -emit-llvm matrix.c -c -o matrix.bc
llc -march=alpha matrix.bc -o matrix.s
Now how to convert matrix.s assembly file into executable file of alpha.
How to do that?
clang can also be used
clang matrix.s -L [additional library locations] -mllvm -Wall -g -L. -Wl,-pie -I. -I[additional include locations] -o [executable output]
Adjust the flags as your needs dictate.
EDIT
Without the need for other includes or libraries just call:
clang matrix.s -mllvm -Wall -g -Wl,-pie -o matrix.out

Use fgsl in fortran: how to compile with gfortran

I am trying to do something basic, but I can't find the relevant information on how to compile. I tried the following without success:
gfortran testintegral.f90 -lgsl -lgslcblas
testintegral.f90:19.6:
use fgsl
1
Fatal Error: Can't open module file 'fgsl.mod' for reading at (1): No such file
The file is taken from http://de.wikibooks.org/wiki/Fortran:_FGSL#Beispiel:_Numerische_Integration (page in german but readily understandable) so I suppose it is OK.
Maybe the syntax of the compilation command is incorrect ?
EDIT:
I edit my initial post so as not to bury important information in the comments.
Those are the paths of the libraries:
sudo find -name '*libgsl.so*'
./usr/lib/libgsl.so.0
./usr/lib/libgsl.so.0.17.0
sudo find -name '*libgslcblas.so*'
./usr/lib/libgslcblas.so.0
./usr/lib/libgslcblas.so.0.0.0
But I still got an error message when doing:
gfortran testintegral.f90 -L/usr/lib -I/usr/include/fgsl -lfgsl -lgsl -lgslcblas
/usr/bin/ld: cannot find -lgsl
/usr/bin/ld: cannot find -lgslcblas
collect2: error: ld returned 1 exit status
Use the -I flag. For example,
gfortran -I/usr/local/fgsl/include testintegral.f90 -lgsl -lgslcblas
All the .mod files in that directory are then included.
EDIT: See also comments below.
Compilation of a file containing modules in gfortran produces two file types: The source file foo.f90 is translated into foo.o. If foo.f90 contains the modules bar and baz, then bar.mod and baz.mod are also generated. They contain the interface information for these modules. Note that there is no required mapping between module and file names (although programming guildelines may require this).
When the statement use fsgl is found, the interface information is read from fsgl.mod. If that file is not found, you get the error message
Can't open module file 'fgsl.mod' for reading at (1): No such file
So, you have to change your order of compilation (possibly through changing a Makefile).
1) the easiest way is
gfortran testintegral.f90 -I/usr/local/include/fgsl -lfgsl
2) this also works
gfortran -I/usr/local/include/fgsl testintegral.f90 -lgsl -lgslcblas -lm
3) I read the log of the make check in the package, the developer used such a way
gfortran -I/usr/local/include/fgsl -g -O2 -c -o test.o testintegral.f90
/bin/bash /path/.../fgsl-1.3.0/libtool --tag=FC --mode=link gfortran -g -O2 -o test test.o /usr/local/lib/libfgsl.la -lgsl -lgslcblas -lm
UPDATE:
First check the linkers for fgsl
pkg-config --libs fgsl
probably will get something like this
-L/usr/local/lib -lfgsl -lgsl -lgslcblas -lm
Then you put the linkers, works for all the cases!
gfortran -I/usr/include/fgsl example.f90 -lfgsl -lgsl -lgslcblas -lm
UPDATE: I answered too soon, here is the best universal method I found:
gfortran `pkg-config --cflags fgsl` testintegral.f90 -o integral `pkg-config --libs fgsl`

Not understanding root of the error

When I'm compiling a shell script there is this error that is being generated,
"No such file or directoryity.c"
I didn't get why there is no space between directory and the name.
I have a file named "Utlity.c", so I think the trailing part of the error message is taken from there. Please help.
Here's the content of the shell script
#!/bin/sh
export LD_LIBRARY_PATH=/usr/local/lib >> ~/.bashrc
gcc MyFol/main.c MyFol/Utility.c -L /usr/local/lib -lgsl -lgslcblas -lm -o SD
gcc -c -O3 -I /usr/local/include/ ivectTmatC/tmatTrain.c ivectTmatC/Utility.c gfortran tmatTrain.o Utility.o /usr/local/lib/liblapacke.a /usr/local/lib/liblapack.a
/usr/local/lib/librefblas.a /usr/local/lib/libgsl.a /usr/local/lib/libgslcblas.a
-o ivectTmat
g++ cosineKernel/cosineKernel.cpp -L /usr/local/lib -lgsl -lgslcblas -lm -o cosineKerne

make library not found

I'm trying to compile a program using a third party library, Omnet++ in my case. Apparently "make" does not find a library, but the path it uses is correct as you can see (in the sense that I can see the library under omnet++ source tree)
pv135168:basic Bob$ opp_makemake
Creating Makefile in /Users/Bob/Code/network_sim/basic... Makefile created, running "make depend" to add dependencies... opp_makedep -Y --objdirtree -I. -f Makefile -P\$O/ -- ./*.cc
pv135168:basic Bob$ make
g++ -c -g -Wall
-fno-stack-protector -m32 -DHAVE_PCAP -DXMLPARSER=libxml
-DWITH_PARSIM -DWITH_NETBUILDER -I.
-I/Users/Bob/Code/omnetpp-4.1/include -o out/gcc-debug//txc1.o txc1.cc g++ -m32 -Wl,-rpath,/Users/Bob/Code/omnetpp-4.1/lib -Wl,-rpath,. -o out/gcc-debug//basic out/gcc-debug//txc1.o -Wl,-all_load
-L"/Users/Bob/Code/omnetpp-4.1/lib/gcc"
-L"/Users/Bob/Code/omnetpp-4.1/lib" -u _tkenv_lib -lopptkenvd
-loppenvird -lopplayoutd -u _cmdenv_lib -loppcmdenvd -loppenvird
-loppsimd -lstdc++
ld: library not found for -lopptkenvd
collect2: ld returned 1 exit status make: *** [out/gcc-debug//basic]
Error 1 pv135168:basic Bob$
It's looking in the following directories for a file called libopptkenvd.dylib or libopptkenvd.a:
/Users/Bob/Code/omnetpp-4.1/lib/gcc
/Users/Bob/Code/omnetpp-4.1/lib
Is that file in one of those directories (or in the standard directories like /usr/lib)? I don't see an indication of that in your output.

Resources