Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
gcc und g++ beim linken
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German)
View previous topic :: View next topic  
Author Message
Egal
Tux's lil' helper
Tux's lil' helper


Joined: 25 Jan 2003
Posts: 99

PostPosted: Thu Jun 19, 2003 8:11 pm    Post subject: gcc und g++ beim linken Reply with quote

Ich habe mal eine Frage zu gcc / g++

soweit ich weiß, müsste man ja eine Library, die man in C benutzen kann,
genauso gut in C++ benutzen können. Mit den meißten Libraries habe ich
auch gar keine Probleme .. aber im Moment weiß ich nicht mehr weiter:

einfach mal folgendes kleines Beispielprogramm: (test.c)
Code:
#include <ffmpeg/avcodec.h>

int main(int argc, char* argv[]) {
    avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
    return 0;
}


wenn ich versuche, das ganze mit:

Code:
gcc test.c -o test -lavcodec


zu kompilieren und auszuführen, geht es problemlos.
Mache ich genau das gleiche mit g++, um c++ code zu
kompilieren, bekomme ich folgenden fehler:

Code:
/tmp/cc42ASJg.o(.text+0x18): In function `main':
: undefined reference to `avcodec_find_encoder(CodecID)'
collect2: ld returned 1 exit status


was geht da beim linken schief ? Die Library selber findet er ja.
Vielleicht kann mir das ja mal jemand erklären ? :oops:

Danke im Vorraus ..
cu Egal
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9625
Location: beyond the rim

PostPosted: Fri Jun 20, 2003 7:10 pm    Post subject: Reply with quote

C und C++ sind nicht wirklich ABI kompatibel, da das "Name Mangling" unterschiedlich ist (notwendig um Funktionen überladen zu können). Bin zwar in C++ etwas aus der Übung, aber um C Funktionen in C++ Code benutzen zu können ist IIRC folgendes Konstrukt nötig:
Code:

<Header Dateien>

#ifdef __cplusplus
extern "C" {
#endif

<dein C++-Code>


Einer der Gründe warum ich C++ nicht sonderlich mag.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum