Ich krieg das gerade nicht auf die Reihe. Das Einbinden per #include verursacht noch keinen Fehler, erst wenn ich auch etwas aus der Bibliothek aufrufe bekomme ich das Problem. Hier ein Beispielcode exemplarisch mit zlib, tritt aber auch mit anderen auf:
C
- #include <stdio.h>
- #include <string.h>
- #include "zlib.h"
- #define buffersize 64
- char a[buffersize]="The quick brown fox jumps over the lazy dog.\0";
- char b[buffersize];
- char c[buffersize];
- uLongf csize=buffersize;
- uLongf usize=buffersize;
- int main(int argc, char **argv){
- printf("%s has %i bytes.\n", a, (int)strlen(a)+1);
- compress((Bytef *)b, &csize, (Bytef *)a, strlen(a)+1);
- printf("compressed size is %lu.\n", csize);
- uncompress((Bytef *)c, &usize, (Bytef *)b, csize);
- printf("%s has %lu bytes.\n", c, usize);
- return 0;
- }
Wenn ich die Zeilen mit compress und decompress auskommentiere, kompiliert es ohne zu meckern.
Kompiliere ich das aber so mit g++ zlib_test.cpp, bekomme ich folgende Fehler:
/usr/bin/ld: /tmp/ccehDWF3.o: in function `main':
zlib_test.cpp:(.text+0x7a): undefined reference to `compress'
/usr/bin/ld: zlib_test.cpp:(.text+0xc5): undefined reference to `uncompress'
collect2: error: ld returned 1 exit status
Was mache ich da falsch?
Ich nutze Linux Mint 21.2.