gcc + gsl 编译c文件

gcc -I/usr/lib/include -c test1.c
gcc -L/usr/lib64 test1.o -lgsl -lgslcblas -lm

# g++ -I/usr/lib/include -c main.cpp
[root@localhost test1]# gcc -I/usr/lib/include -c getmin.cpp
[root@localhost test1]# g++ -I/usr/lib/include -c grayhist.cpp
[root@localhost test1]# g++ -I/usr/lib/include -c sumhist.cpp

g++ -static main.o grayhist.o sumhist.o-lgsl -lgslcblas -lm -o main.out

2.3 Shared Libraries

To run a program linked with the shared version of the library the operating system must be able to locate the corresponding .so file at runtime. If the library cannot be found, the following error will occur:

$ ./a.out
./a.out: error while loading shared libraries:
libgsl.so.0: cannot open shared object file: No such
file or directory

To avoid this error, define the shell variable LD_LIBRARY_PATH to include the directory where the library is installed.

For example, in the Bourne shell (/bin/sh or /bin/bash), the library search path can be set with the following commands:

$ LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
$ export LD_LIBRARY_PATH
$ ./example

In the C-shell (/bin/csh or /bin/tcsh) the equivalent command is,

% setenv LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH

The standard prompt for the C-shell in the example above is the percent character `%’, and should not be typed as part of the command.

To save retyping these commands each session they should be placed in an individual or system-wide login file.

To compile a statically linked version of the program, use the -static flag in gcc,

$ gcc -static example.o -lgsl -lgslcblas -lm

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s