Using spinlocks with gcc - gcc

how can I use pthread_spinlock_t in gcc 4.6.3?
Which flags do I have to specify at compile time?
I'm using Ubuntu 12.04!
Thanks

Just add the option -pthread or -lpthread when linking.
Options -std=c99/c11 will restrict the available library functions to those of C99/C11 standard library
For getting C99/C11 languages features/library and and POSIX (and some BSD and some GNU extension) APIs, one can use -std=gnu99 or -std=gnu11 option to GCC.

Related

How exactly gsl achieved alternative cblas linking feature?

Do you know how can I design the same concept that gsl is using to permit users to switch between various cblas implementation?
AFAIK, cblas dependency that gsl depends on should have been hard-coded into gsl library when gsl itself built.
2.2.2 Linking with an alternative BLAS library
The following command line shows how you would link the same
application with an alternative CBLAS library libcblas.a,
$ gcc example.o -lgsl -lcblas -lm
For the best performance an optimized platform-specific CBLAS library
should be used for -lcblas. The library must conform to the CBLAS
standard. The ATLAS package provides a portable high-performance BLAS
library with a CBLAS interface. It is free software and should be
installed for any work requiring fast vector and matrix operations.
The following command line will link with the ATLAS library and its
CBLAS interface,
$ gcc example.o -lgsl -lcblas -latlas -lm
If the ATLAS library is installed in a non-standard directory use the
-L option to add it to the search path, as described above.
For more information about BLAS functions see BLAS Support.
There's no special concept here – just multiple libraries implementing the same API and having the same ABI.
In other words, you write a program that uses function int do_stuff(char*) from #include foo.h. Libfoo.so is a shared library object that exports the symbol int do_stuff(char*), because it was generated off a program that contains an implementation of int do_stuff(char*).
If you now write a second library that implements all the same symbols that libfoo has, then you've got something that you could use in libfoo's place.
That's all that's happpening here. GSL uses BLAS symbols. BLAS defines what these symbols exactly are (read: their C function signature), so you can use whatever BLAS implementation you want. (assuming all was built with compatible compilers/linkers)
Blas library
gcc -c -Wall -Werror -fpic blas.cpp
gcc -shared -o libblas.so blas.o
GSL library, that is actually using blas but we don't link to it
gcc -c -Wall -Werror -fpic gsl.cpp
gcc -shared -o libgsl.so gsl.o
Example application that links against gsl and blas at the same time
gcc -Wall -o main main.cpp -L../mygsl -lgsl -L../mycblas -lblas

Does DragonEgg support parameters like -fno-builtin in clang?

I have been using clang for quite a while, and I can use clang -fno-builtin -emit-llvm -c hello.c to prevent the generation of llvm built-in functions, such as llvm.memset.
Recently, I switched to gcc with DragonEgg, since the program to be built is originally designed to be compiled with gcc. I searched on the web, but did not find any information about how to set DragonEgg parameters.
Could anyone please give me some help? Any hint or reference will be welcomed. Thanks!
I have figured out a way to use gcc + DragonEgg to achieve similar effects myself.
gcc -S -c -O0 -fplugin=$(DRAGONEGG_SO) -fplugin-arg-dragonegg-emit-ir hello.c -o hello.bc
opt -O3 -disable-simplify-libcalls hello.bc -o hello.bc
$(DRAGONEGG_SO) is the path to dragonegg.so.
Basically the LLVM intrinsics are added by the optimization pass instcombine. With -disable-simplify-libcalls, the LLVM intrinsics are prevented from generating in instcombine.
The method should also work for llvm-gcc to generate LLVM IR without LLVM intrinsics.

Flags for g++ static link when using -nostartfiles -nodefaultlibs -nostdlib

I've been trying to find the proper .a's and related flags for statically linking an app or SO under Linux. I know -static exists, but I can't use it as there's one specific SO I must link to.
To put it another way, I'm looking for the appropriate flags to statically link everything, except for a specific SO.
Thanks.
At my workplace we use -Bstatic and -Bdynamic but they are options to the linker ld. You can specify them with gcc using the -Wl option.
g++ -o app -Wl,-Bstatic -llib1 -llib2 -llib3 -Wl,-Bdynamic -llib4 app.o
Above shows command line for linking with lib1, lib2, and lib3 as static libraries and lib4 as a shared object library.

gcc linker finding both .so and .a in the library path which is chosen?

If I run
gcc a.c -L /usr/lib -lexpat
and both libexpat.a and libexpat.so are in /usr lib which one is used by the linker?
By default the shared library (.so) will be chosen.
If you want to change this behavior, -static gcc option may be used
-static
On systems that support dynamic linking, this prevents linking
with the shared libraries. On other
systems, this option has no effect.

gcc difference between -pthread and -pthreads?

I have a pthreads program. I have to compile it with gcc -pthread in Linux (-pthreads is unrecognized option) and gcc -pthreads in Sun (-pthread is unrecognized option). Why the difference, since it's the same compiler? However, -lpthread works on both, but I heard this isn't always sufficient.
The Solaris -pthreads and Linux -pthread options do equivalent things. Apparently, gcc-4.x series accepts -pthread for Solaris as well.
You do want the -pthread/-pthreads option while compiling because it adds multithreading support in the preprocessor and the linker.

Resources