Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using c library function in c++ code

430 views
Skip to first unread message

Alexey Alexapolsky

unread,
Jun 9, 2000, 3:00:00 AM6/9/00
to
Hi , please help me , I am using linux slakware 7 and egcs 2.91.66
in my c++ program I want to use standard function -
uuid_generate_random(unsigned char*) , from libuuid library , header -
<uuid/uuid.h>
when using it in C - it's ok , but when I use this function in equivalent
C++ code - g++ COMPLAINS :
tiger:~$ g++ -c test.cpp
tiger:~$ g++ -luuid -o test test.o
test.o: In function `main':
test.o(.text+0xb): undefined reference to `uuid_generate_random(unsigned
char *)
Thanx in advance.

Joe Durusau

unread,
Jun 9, 2000, 3:00:00 AM6/9/00
to
Does the header declare the function in question as a C (not c++)
function?? Take a look at the header file and see how it's
declared.

Speaking only for myself,

Joe Durusau

F.R.M.Barnes

unread,
Jun 10, 2000, 3:00:00 AM6/10/00
to
Alexey Alexapolsky <wa...@thukraine.com> wrote:
: Hi , please help me , I am using linux slakware 7 and egcs 2.91.66
: in my c++ program I want to use standard function -
: uuid_generate_random(unsigned char*) , from libuuid library , header -
: <uuid/uuid.h>
: when using it in C - it's ok , but when I use this function in equivalent
: C++ code - g++ COMPLAINS :
: tiger:~$ g++ -c test.cpp
: tiger:~$ g++ -luuid -o test test.o
: test.o: In function `main':
: test.o(.text+0xb): undefined reference to `uuid_generate_random(unsigned
: char *)
: Thanx in advance.

Just a thought; try:
g++ -o test test.o -luuid


-- Fred

Jürgen Hurst

unread,
Jun 13, 2000, 3:00:00 AM6/13/00
to
Alexey Alexapolsky wrote:

> Hi , please help me , I am using linux slakware 7 and egcs 2.91.66
> in my c++ program I want to use standard function -
> uuid_generate_random(unsigned char*) , from libuuid library , header -
> <uuid/uuid.h>
> when using it in C - it's ok , but when I use this function in equivalent
> C++ code - g++ COMPLAINS :
> tiger:~$ g++ -c test.cpp
> tiger:~$ g++ -luuid -o test test.o
> test.o: In function `main':
> test.o(.text+0xb): undefined reference to `uuid_generate_random(unsigned
> char *)
> Thanx in advance.

The header file is a pure C header file. You have to encapsluate it in an
extern "C" statement:

extern "C" {
#include <uuid/uuid.h>
}

Then the names will be correctly (de)mangeled.


Juergen


Felix Natter

unread,
Jun 22, 2000, 3:00:00 AM6/22/00
to
"Alexey Alexapolsky" <wa...@thukraine.com> writes:

> Hi , please help me , I am using linux slakware 7 and egcs 2.91.66
> in my c++ program I want to use standard function -
> uuid_generate_random(unsigned char*) , from libuuid library , header -
> <uuid/uuid.h>
> when using it in C - it's ok , but when I use this function in equivalent
> C++ code - g++ COMPLAINS :
> tiger:~$ g++ -c test.cpp
> tiger:~$ g++ -luuid -o test test.o
> test.o: In function `main':
> test.o(.text+0xb): undefined reference to `uuid_generate_random(unsigned
> char *)
> Thanx in advance.

try wrapping the #include in extern "C" { ... }:
extern "C" {
#include <uuid/uuid.h>
}

--
Felix Natter


0 new messages