g++ fails to link to static library when compilation and link in single command


 
Thread Tools Search this Thread
Top Forums Programming g++ fails to link to static library when compilation and link in single command
# 1  
Old 03-13-2012
g++ fails to link to static library when compilation and link in single command

Hello All,
I've encountered a strange behaviour from g++ that doesn't make sense to me. Maybe you can shed some light on it:

I have a bunch of source files and want to compile them and link them with a static library liba.a located in /usr/local/lib64 into an executable

Approach 1 works fine:
Code:
g++ -c file1.cc
g++ -c file2.cc
g++ -c file3.cc
g++ -o executable file1.o file2.o file3.o -la

Approach 2 doesn't work:
Code:
g++ -o executable file1.cc file2.cc file3.cc -la

That causes a load of undefined references, It's a shame, because method 2 is what my makefile produces.
Can anyone tell me the difference between 1 and 2 and how to fix it?

Thanks a lot,
Bjorn
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

/var/adm/messages (insterface turned off/restored) and link up & link down message.

Hi All I am facing an issue with our new solaris machine. in /var/adm/messages Apr 22 16:43:05 Prod-App1 in.routed: interface net0 to 172.16.101.1 turned off Apr 22 16:43:33 Prod-App1 mac: NOTICE: nxge0 link up, 1000 Mbps, full duplex Apr 22 16:43:34 Prod-App1 mac: NOTICE: nxge0 link... (2 Replies)
Discussion started by: javeedkaleem
2 Replies

2. Solaris

/var/adm/messages (interface turned off/restored) and link up & link down message.

Hi All I am facing an issue with our new solaris machine. in /var/adm/messages root@Prod-App1:/var/tmp# root@Prod-App1:/var/tmp# root@Prod-App1:/var/tmp# cat /var/adm//messages Apr 20 03:10:01 Prod-App1 syslogd: line 25: WARNING: loghost could not be resolved Apr 20 08:24:18 Prod-App1... (0 Replies)
Discussion started by: javeedkaleem
0 Replies

3. UNIX for Advanced & Expert Users

Xserver shared library link is gone

I am administering an Xserver v10.6.8 and I updated the ports using Macports self update. I received this error when calling the program R dyld: Library not loaded: /opt/local/lib/libicuuc.48.dylib Referenced from: /opt/local/lib/R/lib/x86_64/libR.dylib Reason: image not found Trace/BPT... (2 Replies)
Discussion started by: godzilla07
2 Replies

4. UNIX and Linux Applications

Tomcat 6.0 fails to read symlink(symbolic link) file

Hello all experts, Im in a situation where Tomcat simply does not want to read this file through the symlink.... I checked permissions..OK Also checked file & tomcat owner...all OK. This is what I have my /tomcat/conf/Catalina/local/appname.xml <Context> <Resource name="jdbc/black" ... (3 Replies)
Discussion started by: KingaKoopa
3 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Symbolic link not allowed or link target not accessible

Hi everybody, I read about treads realted to this issue but they did not resovle issue given below. Please help me resolve issue given below I have html file under /srv/www/htdocs/actual_folder ls actual_folder/ test.html and following link works... (0 Replies)
Discussion started by: newbielgn
0 Replies

6. Linux

Linux Library symbolic link damaged

Hi, firstly I am not so familiar with linux and i think i have done some damage to the red hat server. It seems that now in command line I am unable to use any basic command whatsoever (ls, move, cp, bash, etc). I was trying to deploy an application and have changed the symbolic link (soft... (1 Reply)
Discussion started by: zaxx
1 Replies

7. UNIX for Dummies Questions & Answers

Difference between hard link and soft link

Hi Experts, Please help me out to find out difference between a hard link and a soft link. I am new in unix plz help me with some example commands ( for creating such links). Regards S.Kamakshi :) (2 Replies)
Discussion started by: kamakshi s
2 Replies

8. Solaris

link a library compiled with SC 5.9 on a machine with SC5.8

Is it possible to link a library compiled on Solaris 10 with SunCompiler 5.9 in a project compiled with SC 5.8 ? Is there an option to "downgrade" the SC5.9 => SC5.8 to be sure of the compatibility ? Thanks 4 your help (2 Replies)
Discussion started by: sarastus
2 Replies

9. UNIX for Dummies Questions & Answers

Difference between hard link and soft link in unix

Hi All, Can any one please explain me what is the difference between hard link and soft link in UNIX. Thanks in advance Raja Chokalingam. (2 Replies)
Discussion started by: RAJACHOKALINGAM
2 Replies

10. Programming

use gcc and link with a library

Hello, J have a problem when I use gcc: This comand works: gcc -shared -fpic -I/usr/include/sys -I/usr/include -L/usr/lib/librt.sl essai1.c mylib.sl but gcc I/usr/include/sys -I/usr/include -L/usr/lib/librt.sl essai2.c -o essai don't work. The first command creates a dynamique... (1 Reply)
Discussion started by: AUBERT
1 Replies
Login or Register to Ask a Question
mpif90(1)								MPI								 mpif90(1)

NAME
mpif90 - Compiles and links MPI programs written in Fortran 90 DESCRIPTION
This command can be used to compile and link MPI programs written in Fortran. It provides the options and any special libraries that are needed to compile and link MPI programs. It is important to use this command, particularly when linking programs, as it provides the necessary libraries. COMMAND LINE ARGUMENTS
-show - Show the commands that would be used without runnning them -help - Give short help -f90=name - Use compiler name instead of the default choice. Use this only if the compiler is compatible with the MPICH library (see below) -config=name - Load a configuration file for a particular compiler. This allows a single mpif90 command to be used with multiple compilers. -compile_info - Show the steps for compiling a program. This option can be used to see what options and include paths are used by mpif90. -link_info - Show the steps for linking a program. This optoin can be used to see what options and libraries are used by mpif90. -profile=name - Use the MPI profiling given by name. See below for details -mpe=name - Use an MPE profiling library. The behavior is similar to using -profile=mpe_name.conf . -echo - Show exactly what this program is doing. This option should normally not be used. others - are passed to the compiler or linker. For example, -c causes files to be compiled, -g selects compilation with debugging on most systems, and -o name causes linking with the output executable given the name name . ENVIRONMENT VARIABLES
The environment variables MPICH_F90 may be used to select different Fortran compiler and linker. Note that since MPICH is built with a particular C and Fortran compiler, change the compilers used can cause problems. Use this only if you could intermix code compiled with the different compilers. COMPATIBLE COMPILERS
The MPI library may be used with any compiler that uses the same lengths for basic data objects (such as long double ) and that uses com- patible run-time libraries. On many systems, the various compilers are compatible and may be used interchangably. There are exceptions; if you use the MPICH_F90 environment variable or the -f90=name command-line argument to override the choice of compiler and encounter prob- lems, try reconfiguring MPICH2 with the new compiler and installing MPICH2 in a separate location. See the installation manual for more details. EXAMPLES
To compile a single file foo.f , use mpif90 -c foo.f To link the output and make an executable, use mpif90 -o foo foo.o Combining compilation and linking in a single command mpif90 -o foo foo.f is a convenient way to build simple programs. SELECTING A PROFILING LIBRARY
The -profile=name argument allows you to specify an MPI profiling library to be used. name can have two forms: A library in the same directory as the MPI library The name of a profile configuration file If name is a library, then this library is included before the MPI library. This allows the simple use of libraries that make use of the MPI profiling interface and that are installed in the same directory as the MPI library. If name.conf is the name of a file in the sysconfdir directory, then this is read and may define the following variables: PROFILE_PRELIB - Libraries (and paths) to include before the MPI library PROFILE_POSTLIB - Libraries to include after the MPI library PROFILE_INCPATHS - C preprocessor arguments for any include files For example, to add /usr/local/myprof/include to the include path and the library libmyprof.a in /usr/local/myprof/lib to the link step, you could create the file myprof.conf with the lines PROFILE_PRELIB="-L/usr/local/myprof/lib -lmyprof" PROFILE_INCPATHS="-I/usr/local/myprof/include" and place it in the sysconfdir directory (this directory is set at configure time when MPICH is built). Then using the command-line argument -profile=myprof will cause these definitions to be added to the relevant compile commands. SEE ALSO
mpicc, mpicxx, mpif90, mpiexec LOCATION
mpif90.txt 11/2/2007 mpif90(1)