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

NAME
sdl-config - script to get information about the installed version of SDL SYNOPSIS
sdl-config [ --prefix[=DIR] ] [ --exec-prefix[=DIR] ] [ --version ] [ --cflags ] [ --libs ] [ --static-libs ] DESCRIPTION
sdl-config is a tool that is used to configure and determine the compiler and linker flags that should be used to compile and link pro- grams, and libraries, and plugins that use SDL. It is also used internally by the m4 macros that are included with SDL. OPTIONS
--cflags Print the compiler flags that are necessary to compile a program or library that uses SDL. --exec-prefix=DIR If specified, use DIR instead of the installation exec prefix that SDL was build with when computing the output for the --exec-pre- fix option. This option must be specified before any of the --cflags, and --libs options. --libs Print the linker flags that are necessary to link a program that uses SDL. --prefix=DIR If specified, use DIR instead of the installation prefix that SDL was built with when computing the output for the --prefix, and --exec-prefix options. This option is also used for the exec prefix if --exec-prefix was not specified. This option must be speci- fied before any of the --cflags, and --libs options. --static-libs Print the linker flags that are necessary to statically link a program that uses SDL. --version Prints the currently installed version of SDL on standard output. EXAMPLES
gcc -o main.o $(sdl-config --cflags) main.c is how you might use sdl-config to compile a C source file for an executable program. gcc -o my_app $(sdl-config --libs) main.o util.o is how you might use sdl-config to link compiled objects into an executable program. AUTHOR
The Simple DirectMedia Layer (SDL) library was written by Sam Lantinga. This manual page was written by Branden Robinson, originally for Progeny Linux Systems, Inc., and the Debian Project. This manual page was modified by Petr Pisar to match original SDL distribution. SDL 1.2 2013-06-19 sdl-config(1)