LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-03-2007, 02:38 PM   #1
mimmi
LQ Newbie
 
Registered: May 2007
Posts: 2

Rep: Reputation: 0
Question c++ gcc


Hi!

I hope this is the right forum for this question (have not posted anything here before)and if somebody can help me I'll be so happy

I have a c++ program that has to be linked to several different lib (so called .a –files for example libName.a) these lib files does not exist in the standard library…so how do I get it right?

For example:

g++ My.cpp –lName

does not work…it complains that it can’t find different things in my c++ program that exist in the libName.a It does not work if I write in the whole path were my different lib files is either…..(ok in my example here I only wrote one lib..)

can anybody pleas help me?

Thanks

by the way I'm using Linux.....
 
Old 05-03-2007, 03:35 PM   #2
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Quote:
Originally Posted by mimmi
Hi!

I hope this is the right forum for this question (have not posted anything here before)and if somebody can help me I'll be so happy

I have a c++ program that has to be linked to several different lib (so called .a –files for example libName.a) these lib files does not exist in the standard library…so how do I get it right?

For example:

g++ My.cpp –lName

does not work…it complains that it can’t find different things in my c++ program that exist in the libName.a It does not work if I write in the whole path were my different lib files is either…..(ok in my example here I only wrote one lib..)
You have to tell the linker where libName.a is. You would think that it would assume it is in ./, but it doesn't. Sooooo....

g++ -L ./ -lName My.cpp

oughta do it. The order doesn't necessarily matter.
 
Old 05-03-2007, 04:04 PM   #3
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
BrianK, that isn't quite mimmi's problem. mimmi says that things don't work even though mimmi specifies the full pathname of the library files.

I'm not sure from mimmi's post whether the problem is that the files themselves are not found, or whether the files are found but the symbols aren't found.

mimmi, for future reference, it is always a good idea to paste the exact text of the error message(s) into your question. It's also a good idea to be as specific as you can (without including megabytes of source code).

I have just whipped up the following sample, which works. Maybe it can help you figure out what went wrong.

Code:
#!/bin/sh

rm -rf wje*

cat > wje1.cpp <<EOD
#include <stdio.h>

void function2();
void function3();

int main(void)
{
  printf("Hello, world!\n");

  function2();
  function3();

  return 0;

} /* main() */
EOD

cat > wje2.cpp <<EOD
#include<stdio.h>

void function2(void)
{
  printf("This is function2().\n");
}
EOD

cat > wje3.cpp <<EOD
#include<stdio.h>

void function3(void)
{
  printf("This is function3().\n");
}
EOD
gcc wje2.cpp -c
gcc wje3.cpp -c

ar -r wje.a wje2.o
ar -r wje.a wje3.o

gcc wje1.cpp wje.a -lstdc++ -o wje1

wje1
The output of that shell script (better not name it something which begins with wje) is:

Code:
Hello, world!
This is function2().
This is function3().
Hope this helps.
 
Old 05-04-2007, 02:53 PM   #4
mimmi
LQ Newbie
 
Registered: May 2007
Posts: 2

Original Poster
Rep: Reputation: 0
ok...I can unfortunatly not check this out right now...(I am not using MY computer right now, are using somebody else's computer´..no libfiles here )I am new to gcc and why do you (wjevans) use gcc and not g++ ? I do not think I just can take
gcc wje2.cpp -c
because I have a lot of .h-files included and doesn't I have to use g++ then together with the path to were the .h-files are? So is it not possible to make all at once with both lib-files and h-files?
Thank you for the help, I'll try this when I get home tomorrow.
 
Old 05-04-2007, 09:06 PM   #5
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Quote:
Originally Posted by mimmi
ok...I can unfortunatly not check this out right now...(I am not using MY computer right now, are using somebody else's computer´..no libfiles here )I am new to gcc and why do you (wjevans) use gcc and not g++ ? I do not think I just can take
gcc wje2.cpp -c
because I have a lot of .h-files included and doesn't I have to use g++ then together with the path to were the .h-files are? So is it not possible to make all at once with both lib-files and h-files?
Thank you for the help, I'll try this when I get home tomorrow.
.h files should be included in the .cpp, therefore there's no need to do anything with them on the command line. If the .h files are not in ./ or in your include path, you can specify where by using the -I (that's a capital 'i' in case you're using the same font I am where i's and l's look the same) option (-I specifies additional include paths).

All this talk is somewhat useless as we're speculating until we see the error message.

Are these libraries that you built or did they come from somewhere else? Do you know how they were built?

Are you familiar with makefiles? Are you using a makefile? How are you compiling if not with a makefile?

Last edited by BrianK; 05-04-2007 at 09:07 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Tools: GCC 3.4.6, Final GCC 3 Release LXer Syndicated Linux News 0 05-30-2006 02:21 AM
gcc wont install, 'failed dependencies: glibc-devel is needed by gcc-3.3.3-41' TdlSnare SUSE / openSUSE 3 11-29-2004 02:13 PM
running software built with gcc 3.0.2 on Redhat 8 - gcc 3.2 dst1989 Linux - Software 3 03-08-2004 10:23 PM
a doubt with host gcc and arm-linux-gcc renjithgopal Linux - General 1 09-11-2003 04:02 PM
export CC=/usr/bin/gcc-3.2 - switch gcc version? ferreter Linux - Software 1 08-20-2003 12:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration