How to compile FastCGI++ Code? - gcc

What command should I use to compile FastCGI++ Code?
The documented command gives me several errors.
user#user:~/code$ g++ -o main.fcgi main.cpp pkg-config –libs –cflags fastcgi++
g++: error: pkg-config: No such file or directory
g++: error: –libs: No such file or directory
g++: error: –cflags: No such file or directory
g++: error: fastcgi++: No such file or directory

Sometimes FastCGI++ is compiled with it's Boost libraries dynamically. This means, afaik, that you need to link to them as well when you compile your code.
g++ -o main.fcgi main.cpp -lfastcgipp -lboost_system -lboost_thread

You need backticks for you pkg-config command
g++ -o main.fcgi main.cpp `pkg-config --libs --cflags fastcgi++`
In my system, this command is interpreted as
g++ -o main.fcgi main.cpp -I/usr/local/include -pthread -L/usr/local/lib -lfastcgipp -lboost_thread-mt -lboost_system-mt -lboost_date_time-mt

Related

automake putting object files after libraries

src/Makefile.am:
myproj_CXXFLAGS = -fopenmp -O3 -std=c++17 -g -I/home/software/miniconda3/include -I$(top_srcdir)/external
myproj_LDFLAGS = -L/home/software/miniconda3/lib -Wl,-rpath=/home/software/miniconda3/lib -fopenmp -lz -ligraph -pthread
bin_PROGRAMS = myproj
myproj_SOURCES = gfa.cpp graph.cpp myproj.cpp gfa.h graph.h
bindir = $(top_srcdir)/bin
This builds the object files just fine, but when building the target, it tries running
g++ -fopenmp -O3 -std=c++17 -g -I/home/software/miniconda3/include -I../external -g -O2 -L/home/software/miniconda3/lib -Wl,-rpath=/home/software/miniconda3/lib -fopenmp -lz -ligraph -pthread -o myproj myproj-gfa.o myproj-graph.o myproj-komb.o
The issue with this is that the object files come after the library files, which causes the error
/home/software/miniconda3/lib/libz.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
I can easily fix this by adding the -lz -ligraph flags at the very end, but how can I get automake to add the LDFLAGS after the object files as opposed to before?
That's because you're using the wrong variable. To pass libraries, you should use myproj_LDADD, not myproj_LDFLAGS.

Static library gcc - library not found

I want to create static library and something goes wrong. I have makefile:
static: main.c tree.c
gcc -c -Wall tree.c -o tree.o
ar crs libtree.a tree.o
gcc -Wall -static main.c -L. -ltree -o main
./main
When I write "make static", it shows me:
gcc -c -Wall tree.c -o tree.o
ar crs libtree.a tree.o
gcc -Wall -static main.c -L. -ltree -o main
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [static] Error 1
It created files: tree.o and libtree.a. I don't know why it doesn't want to find a library. Do you know how to solve it?
Most probably, your system is not set up for static linking. Most newer Linux distributions aren't as static linking is highly discouraged.
Look for a package named glibc-static or similar and install.
In case your system is not Linux (could be MacOS X as well, you didn't state that) - You're doomed. Static linking is not supported on that platform at all.

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`

gcc file not found issue

I'm trying to compile a simple little test program. and I'm getting errors:
MacBook-Air:Untitled user$ ls
main.c makefile utils.c utils.h
MacBook-Air:Untitled user$ make
avr-gcc -I. -g -mmcu=atmega640 -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -Wstrict-prototypes -Wa,-ahlms=main.lst -c main.c -o main.o
make: avr-gcc: No such file or directory
make: *** [main.o] Error 1
MacBook-Air:Untitled user$
What file is gcc complaining about? main.c does exist in the same directory as the makefile so I'm confused.
It's not the C file it can't find, it's the C compiler (avr-gcc). Is it defined in the makefile? E.g. CC=avr-gcc ? You could try replacing that with CC=gcc

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