Portaudio - Where is the main.c file? - compilation

I am trying to install portaudio and to link it with other libraries as described here:http://www.portaudio.com/docs/v19-doxydocs/compile_linux.html
by using the following code:
{gcc main.c libportaudio.a -lrt -lm -lasound -ljack -pthread -o YOUR_BINARY}
The problem is that I cannot find the main.c file.
If anybody could advise I would be very grateful!

Related

executable do not run after static linking with library

In my Makefile, I have tried build a code static linking with a library from another project I have in my computer. I have this instruction:
game: Input.o Image.o Renderer.o Surface.o Main.o
g++ -g -L ${sdl_library} -L ${lib_netpbm_library} -o release/game2d build/Input.o build/Image.o build/Renderer.o build/Surface.o build/Main.o -l:libnetpbm.a -l:libSDL2.a -l:libSDL2main.a -lGL -lGLEW -lm
It builds with no error or warning. But when I try run the generated executable, I got this error:
./game2d: error while loading shared libraries: libnetpbm.a: cannot open shared object file: No such file or directory
What I am missing here?
The issue was in fact in the way I was building the library. I change the Makefile from this:
libnetpbm: ${obj_dir}/netpbm.o ${obj_dir}/bitmap.o ${obj_dir}/graymap.o ${obj_dir}/pixmap.o
g++ -g -shared -o ${release_dir}/libnetpbm.so ${obj_dir}/netpbm.o ${obj_dir}/bitmap.o ${obj_dir}/graymap.o ${obj_dir}/pixmap.o -Wl,--out-implib,${release_dir}/libnetpbm.a
to that:
libnetpbm: ${obj_dir}/netpbm.o ${obj_dir}/bitmap.o ${obj_dir}/graymap.o ${obj_dir}/pixmap.o
ar rcs ${release_dir}/libnetpbm.a ${obj_dir}/netpbm.o ${obj_dir}/bitmap.o ${obj_dir}/graymap.o ${obj_dir}/pixmap.o
g++ -g -shared -o ${release_dir}/libnetpbm.so ${obj_dir}/netpbm.o ${obj_dir}/bitmap.o ${obj_dir}/graymap.o ${obj_dir}/pixmap.o

How to cgo link to libraries built with LLVM's libc++

I would like to CGO link my go program to a c++ static library linked to LLVM's libc++. With GNU's libstdc++, everything works fine.
I am calling go compiler as follows:
CGO_CXXFLAGS="-stdlib=libc++ -I/usr/lib/clang/12.0.0/include -I/usr/local/include -I/usr/include" CGO_LDFLAGS="-stdlib=libc++ -L/usr/lib/clang/12.0.0/lib -L/usr/local/lib -L/usr/lib -L/usr/lib/x86_64-linux-gnu -lpthread -lrt -lc++ -lm -lc" go test --ldflags '-extldflags "-static"' -c -a .
I was missing -lc++ -lc++abi.

Link error with qpid-proton-0.17.0

When I build my qpid-proton-0.17.0 program I get this link error:
undefined reference to proton::event_loop::inject(std::function<void ()>)
Here is how I build:
g++ -std=c++14 myprog.cpp -o myprog -lqpid-proton-cpp -lboost_system -lcrypto -lssl
Am I missing a library?
Also, without -std=c++14 or -std=c++11 the link issue goes away. But I will need -std=c++11 at least.
I rebuilt qpid-proton-0.17.0 libraries with -DCMAKE_CXX_FLAGS=-std=c++11 and that fixed my issue.

GTK3 program no longer compiles - GCC "undefined reference" at link time

So I was merrily learning GTK+ programming with 3.0 in Ubuntu 11.04, and even got a working ruler program running. It compiled with my makefile perfectly.
I took some time away from it, upgraded to 11.10, and now have come back to it. But, alas, when I try to build the program, I get a lot of "undefined reference" errors to pretty much every gtk call in my program. Compiling is fine - the issue is at link time.
The project can be found here: https://github.com/zjmichen/ruler
I've tested it and it compiled fine.
superman#superman-mint ~/work/zjmichen-ruler-e783fe1 $ make
gcc -c -Wall `pkg-config --cflags --libs gtk+-3.0` main.c
gcc -c -Wall `pkg-config --cflags --libs gtk+-3.0` window.c
gcc -c -Wall `pkg-config --cflags --libs gtk+-3.0` graphics.c
gcc -c -Wall `pkg-config --cflags --libs gtk+-3.0` mouse.c
gcc `pkg-config --cflags --libs gtk+-3.0` main.o window.o graphics.o mouse.o -o zruler
superman#superman-mint ~/work/zjmichen-ruler-e783fe1 $
But this was on Linux Mint. Here you've got the arguments produced by pkg-config
-pthread -DGSEAL_ENABLE -I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gtk-3.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pixman-1 -pthread -L/usr/lib/x86_64-linux-gnu -lgtk-3 -lgdk-3 -latk-1.0 -lcairo-gobject -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lm -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0
I've also did a quick test on Ubuntu 11.10 and indeed it doesn't compile. I'll take a better look this evening.
So I did test it on Ubuntu and changed the line 14 in the makefile to
$(CC) $(OBJS) $(GTKFLAGS) -o $(NAME)
this changes the order of object files and libraries that are being linked. I have no idea why this problem occurs on the new Ubuntu. Maybe it is because it is a different version of gcc. On my linux mint gcc is version 4.5.2 on ubuntu 11.10 it is 4.6.1
Unfortunately I currently don't have access to a running Linux machine with GTK3.0 installed, but looking at your code I noticed the inclusion of X11/xlib.h in main.c. Since you are not using X11 code anywhere in your code and you are using 'pkgconfig ... gtk+-3.0' instead of gtk+-X11-3.0, I assume you could remove that include statement. If you do need the X11 libraries the make sure it is listed in the compiler flags. I hope this helps :)

how to link static library into dynamic library in gcc

Under gcc (g++), I have compiled a static .a (call it some_static_lib.a) library. I want to link (is that the right phrase?) this .a file into another dynamic library (call it libsomeDyn.so) that I'm building. Though the .so compiles, I don't see content of .a under .so using nm command:
/usr/bin/g++ -fPIC -g -O2 -Wall -Werror -pipe -march=pentium3
-mtune=prescott -MD -D_FILE_OFFSET_BITS=64 -DLINUX -D_GNU_SOURCE -D_THREAD_SAFE -I../../../../../../../../ -I../../../../../../../..//libraries -Wl,-rpath,/usr/lib -o libsomeDyn.so some.o another.o some_static_lib.a -shared -Wl -x
-Wl,-soname,libsomeDyn.so
I do not see functions under some_static_lib.a under libsomeDyn.so. What am I doing wrong?
Static libraries have special rules when it comes to linking. An object from the static library will only be added to the binary if the object provides an unresolved symbol.
On Linux, you can change that behavior with the --whole-archive linker option:
g++ -Wl,--whole-archive some_static_lib.a -Wl,--no-whole-archive
For every one that comes across that problem like me (and has not understand the answer properly): here is a short howto generate a dynamic library (libmylib.so) from a static one (mylib.a):
1.) create a mylib.c file that only imports the mylib.h file
2.) compile this mylib.c to mylib.o with
gcc -c -fPIC mylib.c -o mylib.o
3.) generate a dynamic library with the following command:
gcc --whole-archive -shared -Wl,-soname,libmylib.so -o libmylib.so mylib.o mylib.a
That worked at least for me, turning a static library (compiled with -fPIC) to
a dynamic library. I'm not sure wether this will work for other libraries too.

Resources