-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
c++ compile (g++) fails #2
Comments
Hello extern "C" is used when fpc.c is compiled as c but then included by a c++ application To make it work you should either compile fpc.c seperately as c application
and then link it with c++
or if you want to compile both with g++ you should remove extern "C" |
Also you should notice that fpc.c uses variable length arrays that they are not present in standard c++. They are included only in standard c (C99 and above). So it can be compiled as c++ only with compilers that support variable length arrays as extension like g++ and clang++. |
Thanks for the info. I made a static lib Makefile for fpc.c by using g++ and it works. Probably will use it instead of just using the #include "fpc.c" trick. |
Makefile for libfpc.a: CC = g++ INC = -I./ #Lib for fpc.c #Compiling every *.c to *.o dirmake: clean: rebuild: clean build |
Undefined references during linking and then some warnings. I don't understand why linkage fails, because header while has extern "C" linkage.
When I include the c file directly (#include fpc.c) in my project then it builds.
Below is the log of compile. I edited the make file to use C++ compiler and changed the std library option.
g++ -Wall -O2 -std=c++11 -DNDEBUG fpc.c cli.c -o fpc
fpc.c: In function ‘void byte_count(U8*, int, U32*, int)’:
fpc.c:412:14: warning: comparison of integer expressions of different signedness: ‘U32’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
412 | for(a = 0;a < (len & (~7));a += 8){
| ~~^~~~~~~~~~~~~~
fpc.c:431:9: warning: comparison of integer expressions of different signedness: ‘U32’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
431 | for(;a < len;)
| ~~^~~~~
fpc.c:433:14: warning: comparison of integer expressions of different signedness: ‘U32’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
433 | for(a = 0;a < sym_num;a++)
| ~~^~~~~~~~~
fpc.c: In function ‘void sort_inc(Fsym*, int)’:
fpc.c:442:14: warning: comparison of integer expressions of different signedness: ‘U32’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
442 | for(a = 0;a < num;a++){
| ~~^~~~~
fpc.c:460:14: warning: comparison of integer expressions of different signedness: ‘U32’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
460 | for(a = 0;a < num;a++){
| ~~^~~~~
fpc.c:466:14: warning: comparison of integer expressions of different signedness: ‘U32’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
466 | for(a = 0;a < num;a++){
| ~~^~~~~
fpc.c: In function ‘int construct_dec_table(U8*, Dnode*, int)’:
fpc.c:490:14: warning: comparison of integer expressions of different signedness: ‘U32’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
490 | for(a = 0;a < sym_num;a++){
| ~~^~~~~~~~~
fpc.c:505:14: warning: comparison of integer expressions of different signedness: ‘U32’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
505 | for(a = 0;a < sym_num;a++){
| ~~^~~~~~~~~
fpc.c: In function ‘void construct_enc_table(Enode*, Fsym*, int)’:
fpc.c:539:14: warning: comparison of integer expressions of different signedness: ‘U32’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
539 | for(a = 0;a < num;a++){
| ~~^~~~~
fpc.c:548:14: warning: comparison of integer expressions of different signedness: ‘U32’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
548 | for(a = 0;a < num;a++){
| ~~^~~~~
fpc.c: In function ‘U32 write_prefix_descr(Enode*, U8*, int)’:
fpc.c:676:14: warning: comparison of integer expressions of different signedness: ‘U32’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
676 | for(a = 0;a < sym_num;a++){
| ~~^~~~~~~~~
fpc.c:680:13: warning: comparison of integer expressions of different signedness: ‘U32’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
680 | while(a+1 < sym_num && previous == lookup[a+1].len)
| ~~~~^~~~~~~~~
fpc.c: In function ‘int FPC_compress_block(void*, const void*, int, int)’:
fpc.c:913:14: warning: comparison of integer expressions of different signedness: ‘U32’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
913 | for(a = 0;a < sym_num;a++)
| ~~^~~~~~~~~
fpc.c:924:14: warning: comparison of integer expressions of different signedness: ‘U32’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
924 | for(a = 0;a < sym_num && s[a].freq == 0;a++);
|
^~~~~~~~~fpc.c:951:21: warning: comparison of integer expressions of different signedness: ‘U32’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
951 | if(compressed_size >= size){
| ~~~~~~~~~~~~~~~~^~~~~~~
fpc.c: In function ‘size_t comp_adaptive(void*, void*, size_t)’:
fpc.c:1038:41: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
1038 | for(int c = 1;c <= MBLOCK && (cSTEP) <= inlen - a;c++){
| ~~~~~~~~~^~~~~~~~~~~~
fpc.c: In function ‘size_t FPC_compress(void, void*, size_t, int)’:
fpc.c:77:23: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
77 | #define MIN(A,B) ((A) < (B)?(A):(B))
| ~~~~^~~~~
fpc.c:1095:14: note: in expansion of macro ‘MIN’
1095 | U32 step = MIN(inlen,bsize);
| ^
/usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: /tmp/ccwLzlL2.o: in function
dec_file(_IO_FILE*, _IO_FILE*) [clone .part.0]': cli.c:(.text+0xae): undefined reference to
FPC_decompress_block'/usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: /tmp/ccwLzlL2.o: in function
comp_file(_IO_FILE*, _IO_FILE*, int)': cli.c:(.text+0x2cc): undefined reference to
FPC_compress'/usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: /tmp/ccwLzlL2.o: in function
bench_file(_IO_FILE*, unsigned int, int)': cli.c:(.text+0x528): undefined reference to
FPC_compress'/usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: cli.c:(.text+0x543): undefined reference to
FPC_compress' /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: cli.c:(.text+0x55e): undefined reference to
FPC_compress'/usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: cli.c:(.text+0x577): undefined reference to
FPC_compress' /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: cli.c:(.text+0x5d5): undefined reference to
FPC_decompress'/usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: cli.c:(.text+0x5f0): undefined reference to
FPC_decompress' /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: cli.c:(.text+0x60b): undefined reference to
FPC_decompress'/usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: cli.c:(.text+0x624): undefined reference to `FPC_decompress'
collect2: error: ld returned 1 exit status
make: *** [Makefile:5: fpc] Error 1
The text was updated successfully, but these errors were encountered: