Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How to compile using library

Reply
Thread Tools

How to compile using library

 
 
stachurr@iem.pw.edu.pl
Guest
Posts: n/a
 
      12-13-2005
Hello

I'm new in C, And I want to compile program which use extern function.
How to do it because I always got error.
Undefined first referenced
symbol in file
greet /tmp/cchAXHfp.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

first I did "gcc -G -o libgreet.so greet.c" and it is ok.
Later I tried:
gcc -G -lgreet mix.c
gcc -L/local/data02/app/repapp/test/gp
-I/local/data02/app/repapp/test/gp mix.c
gcc -L/local/data02/app/repapp/test/gp mix.c

And always I got error.

Thx
Robert

bash-2.05$ cat greet.h
char *greet();

bash-2.05$ cat greet.c
#include "greet.h"

char *greet() {
return ((char *) "Hello!");
}


bash-2.05$ cat mix.c
#include <stdio.h>
extern char *greet();
int main() {
char *greeting = greet();
printf ("aa\n");
return (0);
}

 
Reply With Quote
 
 
 
 
usenet@zevv.nl
Guest
Posts: n/a
 
      12-13-2005
> I'm new in C, And I want to compile program which use extern function.
> How to do it because I always got error.
> Undefined first referenced
> symbol in file
> greet /tmp/cchAXHfp.o
> ld: fatal: Symbol referencing errors. No output written to a.out
> collect2: ld returned 1 exit status
>
> first I did "gcc -G -o libgreet.so greet.c" and it is ok.
> Later I tried:
> gcc -G -lgreet mix.c
> gcc -L/local/data02/app/repapp/test/gp
> -I/local/data02/app/repapp/test/gp mix.c
> gcc -L/local/data02/app/repapp/test/gp mix.c


<-- snip code -->

Simply linking both files to one executable :

$ gcc -c greet.c -o greet.o # compile file 1
$ gcc -c mix.c -o mix.o # compile file 2
$ gcc mix.o greet.o -o greet # link both object files into binary
$ ./greet # run binary



--
:wq
^X^Cy^K^X^C^C^C^C
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
compile directive for conditional compile for Java 1.4 versus Java 5 timjowers Java 7 02-02-2011 12:08 AM
Compile versus not compile (VS 2005)?? stupid48@gmail.com ASP .Net 1 04-11-2008 08:24 PM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
Unable to compile using boost::date_time library ufnuceda@gmail.com C++ 0 01-14-2006 02:03 AM



Advertisments