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
LINK(3) 								 1								   LINK(3)

link - Create a hard link

SYNOPSIS
bool link (string $target, string $link) DESCRIPTION
link(3) creates a hard link. PARAMETERS
o $target - Target of the link. o $link - The link name. RETURN VALUES
Returns TRUE on success or FALSE on failure. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.0 | | | | | | | This function is now available on Windows plat- | | | forms (Vista, Server 2008 or greater). | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 Creating a simple hard link <?php $target = 'source.ext'; // This is the file that already exists $link = 'newfile.ext'; // This the filename that you want to link it to link($target, $link); ?> NOTES
Note This function will not work on remote files as the file to be examined must be accessible via the server's filesystem. Note For Windows only: This function requires PHP to run in an elevated mode or with the UAC disabled. SEE ALSO
symlink(3), readlink(3), linkinfo(3). PHP Documentation Group LINK(3)