When linking targets/tests/md5.c's object with the other lib objects ,the linker used is gcc, which can't link mixed c/c++ objects. I tried setting CC=g++, which got around this issue but md5.c has casting errors that g++ complains about. I can't seem to find a way to specify the appropropriate linker for when the objects are mixed c/c++.
my platform is Ubuntu 12.04 64bit.
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 Copyright (C) 2011 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 Copyright (C) 2011 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
./configure summary result:
Configuration summary ===================== xlslib (version 2.4.0) is now configured as follows: * Compilation environment CC = gcc -std=gnu99 CFLAGS = -g -O2 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers CPP = gcc -std=gnu99 -E CPPFLAGS = CXX = g++ CXXFLAGS = -g -O2 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers LD = /usr/bin/ld -m elf_x86_64 LDFLAGS = LIBS = INSTALLFLAGS = BINDIR = * xlslib options Development-time debugging: no Allow profiling using gprof: no Allow profiling using prof: no Allow test coverage analysis using gcov: no Build: release (default optimizations) Settings: -----------------------------------------------------------------------
I never heard of a problem linking c and c++ objects - this has been working for years on all kinds of platforms. Unfortunately I'm on a Mac, and OSX uses llvm/clang now, not gcc. I just pulled the source from sourceforge, and did ./configure & make. This is what I got for the test compile
Making all in test
g++ -DHAVE_CONFIG_H -I. -I../../src/common -I../../src -g -O2 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -MT mainCPP.o -MD -MP -MF .deps/mainCPP.Tpo -c -o mainCPP.o mainCPP.cpp
mv -f .deps/mainCPP.Tpo .deps/mainCPP.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I../../src/common -I../../src -g -O2 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -MT md5.o -MD -MP -MF .deps/md5.Tpo -c -o md5.o md5.c
mv -f .deps/md5.Tpo .deps/md5.Po
/bin/sh ../../libtool --tag=CXX --mode=link g++ -g -O2 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -static -lstdc++ -o testCPP mainCPP.o md5.o ../../src/libxls.la
libtool: link: g++ -g -O2 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -o testCPP mainCPP.o md5.o -Wl,-bind_at_load -lstdc++ ../../src/.libs/libxls.a -liconv
gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I../../src/common -I../../src -g -O2 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -MT mainC.o -MD -MP -MF .deps/mainC.Tpo -c -o mainC.o mainC.c
mv -f .deps/mainC.Tpo .deps/mainC.Po
/bin/sh ../../libtool --tag=CC --mode=link gcc -std=gnu99 -g -O2 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -static -lstdc++ -o testC mainC.o md5.o ../../src/libxls.la
libtool: link: gcc -std=gnu99 -g -O2 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -o testC mainC.o md5.o -lstdc++ ../../src/.libs/libxls.a -liconv
Hi, I am getting similar errors when compiling the library with the sources. It gives undefined references to standard library objects like std:basic_string and __cxa_allocate_exception etc.
Using:
Kubuntu 14.0
gcc/g++ 4.8.2
x86_64
I first though my LD_LIBRARY_PATH had some issue, which turns out that ubuntu does not allow to be set globally and can only be set in the environment from an interactive session. That the issue still persisted. So I rechecked the logs and make seems to be invoking gcc with libraries for c++ (namely libstdc++), which could be the issue?
make log attached.
Try pulling the 'trunk' source from svn. I made several changes the past 18 months, and really need to spin another release. I can try to make md5.c a c++ file, but I only test on a Mac, and its using the last clang compiler, so am dreading all the problems people with older compilers will have.
Will perform an svn checkout. I was able to compile it properly but had to do a few modifications to xlslib.h. Maybe this is helpful to you in some way.
First like I said I had a lot of unresolved references for stadard objects which was because the gcc was trying to ling libstdc++ (which is a c++ library). I believe this is an issue with the ./configure script. So I forced the CC flag to g++ instead of the configure-detected gcc -std=gnu99 like this.
CC=g++ ./configure
Which allowed me to proceed further in the compile/link process. I then ran into the same issue discribed in the bug where I got errors in the md5.c file. The specific errors were casting error for dynamic allocation using malloc. Obviously the newer compilers require static casting when mixing void * with char *. So I placed static_cast there to proceed further.
I lasts hickup came when compiling mainC.c. For some reason, the "extern" keyword before the function definitions with in the extern "C" clause in the xlslib.h was not being invoked and I had to define CPP_BRIDGE_XLS in the mainC.c to include all the declarations properly.
Thanks for the support. This library is much needed.
Will perform an svn checkout. I was able to compile it properly but had to do a few modifications to xlslib.h. Maybe this is helpful to you in some way.
First like I said I had a lot of unresolved references for stadard objects which was because the gcc was trying to ling libstdc++ (which is a c++ library). I believe this is an issue with the ./configure script. So I forced the CC flag to g++ instead of the configure-detected gcc -std=gnu99 like this.
CC=g++ ./configure
Which allowed me to proceed further in the compile/link process. I then ran into the same issue discribed in the bug where I got errors in the md5.c file. The specific errors were casting error for dynamic allocation using malloc. Obviously the newer compilers require static casting when mixing void * with char *. So I placed static_cast there to proceed further.
I lasts hickup came when compiling mainC.c. For some reason, the "extern" keyword before the function definitions with in the extern "C" clause in the xlslib.h was not being invoked and I had to define CPP_BRIDGE_XLS in the mainC.c to include all the declarations properly.
Thanks for the support. This library is much needed.
I performed an svn checkout so firstly...
There seems to be an issue with the Makefile.in. The timestamps may be off which is why make was failing. Had to do
make all AUTOCONF=: AUTOHEADER=: AUTOMAKE=: ACLOCAL=:
And I still get the good old unreesolved references during build when I do a vanilla configure and the same malloc error when I force g++ during configure using:
CC=g++ ./configure
Another issue I ran into, could be related to this.
configure is not able to detect PRAGMA_PACK which disables formulas.
Right, so if your system does not support the 'pack' attribute on structures, which tells the compiler to not introduce any extra unused space for efficiency, then formulas will not work. That whole section of code COULD be re-written to essentially have to structs, one "real" and the other just an in-memory blob that code packs - a feature that would be a huge amount of work. If someone wants to volunteer to do it, great!
Yes, but the architecture does supported structure packing. I checked the
config.log and what happens is the conftest.c uses malloc which is not
casted to a variable type from void*. So when I compile with g++ this
generates an obvious error.
Using -fpermissive fixes the error but its not an elegant solution. Seems
like all roads lead to the same thing. C/C++ mixing specifically on Ubuntu
variants.
On Oct 21, 2014 6:58 PM, "David Hoerl" dhoerl@users.sf.net wrote:
Related
Bugs: #52
Yes, but the architecture does supported structure packing. I checked the config.log and what happens is the conftest.c uses malloc which is not casted to a variable type from void*. So when I compile with g++ this generates an obvious error.
Using -fpermissive fixes the error but its not an elegant solution. Seems like all roads lead to the same thing. C/C++ mixing specifically on Ubuntu variants.
Try replacing your "targets" folder with the attached, make sure you ./configure, then try doing a make. The signatures may fail if you run "make check" - some of mine are out of date - and not sure if the switch to c++ causes any changes. Let me know how it goes.
Last edit: David Hoerl 2014-10-21
Hmmm, still the same errors in mainC.c and md5.c
On Oct 22, 2014 2:52 AM, "David Hoerl" dhoerl@users.sf.net wrote:
Related
Bugs: #52
Did you clean first, then do a ./configure? There is a new file there, md5cpp.cpp which should be compiled and linked into all 3 Test cpp processes. If that fails, do a fresh download of the source from svn, then ./configure, then make. Something has to process the Makefile.xx files in Test, to create the Makefile. It sounds like you have an old Makefile. Look at the Makefile.in (I think in, maybe am - I updated both)
Will do in the morning, but I just wanted to say, thank you so much. And if
you guys require any help going forward with this awesome library, count me
in.
On Oct 22, 2014 11:11 PM, "David Hoerl" dhoerl@users.sf.net wrote:
Related
Bugs: #52
Did a fresh svn checkout and then installed the targets.zip you provided.
Getting some errors in mainC.c
Attached is the make.log.
I fixed these by declaring CPP_BRIDGE_XLS, put using namespace xls... in mainC.c before #include "xlslib.h"
Also I see that configure fails to configure pragma pack because g++ tries to compile conftest.c (a C file) which has memchr function returning a void pointer to a char (or something). its still requires -fpermissive to get pragma pack (and thus get formula capabilities).
I am thinking, compiling for the lowest subset of C is cause all of these issues. Would it be possible to configure for only C++ as well as the C subset? and let the user choose which one they want via a flag or something?