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
ln(1)							      General Commands Manual							     ln(1)

Name
       ln - link to a file

Syntax
       ln [ -f ] [ -i ] [ -s ] name1 [name2]
       ln [ -f ] [ -i ] [ -s ] name ... directory

Description
       A  link is a directory entry referring to a file.  A file, together with its size and all its protection information may have several links
       to it.  There are two kinds of links: hard links and symbolic links.

       By default makes hard links.  A hard link to a file is indistinguishable from the original directory entry.  Any  changes  to  a  file  are
       effective independent of the name used to reference the file.  Hard links may not span file systems and may not refer to directories.

       Given  one or two arguments, creates a link to an existing file name1.  If name2 is given, the link has that name.  The name2 may also be a
       directory in which to place the link.  Otherwise it is placed in the current directory.	If only the directory is specified,  the  link	is
       made to the last component of name1.

       Given  more  than two arguments, makes links to all the named files in the named directory.  The links made have the same name as the files
       being linked to.

Options
       -f   Forces existing destination pathnames to be removed before linking without prompting for confirmation.

       -i   Write a prompt to standard output requesting information for each link that would overwrite an existing file.  If  the  response  from
	    standard input is affirmative, and if permissions allow, the link is done. The -i option has this effect even if the standard input is
	    not a terminal.

       -s   Creates a symbolic link.

	    A symbolic link contains the name of the file to which it is linked.  The referenced file is used when an operation  is  performed	on
	    the  link.	 A  on a symbolic link returns the linked-to file.  An must be done to obtain information about the link.  The call may be
	    used to read the contents of a symbolic link.  Symbolic links may span file systems and may refer to directories.

See Also
       cp(1), mv(1), rm(1), link(2), readlink(2), stat(2), symlink(2)

																	     ln(1)