Re: extern "C" and undefined reference



Andrew Pantyukhin wrote:
7zip developers converted some code from C++ to C,
while leaving the main stand-alone lzma app in C++.
They use 'extern "C" { }' blocks around #include's
referencing C headers.

Everything compiles fine, but "undefined reference"
errors appear at linkage. The undefined references
are to the C functions included from withing those
'extern "C"' wrappers. I tried to remove the
wrappers from some files and the amount of errors
decreased a bit. Is there a better workaround?

Google came up with two results: remove the wrappers
or use c++ instead of cc. I'm already using c++.

Many of the C headers are available in a different form for C++ programs. For example, in a C++ program you can #include <cstdio> instead of <stdio.h>.

You can use nm(1) on the .o files to see where the problem comes from.

Diomidis
_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • extern "C" and undefined reference
    ... referencing C headers. ... Everything compiles fine, but "undefined reference" ... wrappers from some files and the amount of errors ...
    (freebsd-hackers)
  • Re: Undefined reference to ... error under gcc
    ... > The program is composed of a single .c file that compiles without error ... >: undefined reference to `sf_strerror' ... Linking and libraries are not things which are part of standard C ... information (I use my own C++ WAV file library, not libsndfile, for WAV ...
    (comp.lang.c)
  • Unresolved Symbols from C++ Code
    ... I'm writing a bunch of C++ code that is going to be linked into a program ... My C++ code compiles and executes without error in my C++ test harness. ... things fail once I move to gcc. ... undefined reference to `operator delete' ...
    (comp.lang.cpp)
  • Re: Undefined reference to ... error under gcc
    ... > The program is composed of a single .c file that compiles without error ... >: undefined reference to `sf_strerror' ... > - When using gcc under a gygwin environment ... together the compiled files and libraries to create the final executable. ...
    (comp.lang.c)
  • A curious problem with make
    ... : undefined reference to `Thread::Thread' ... compiles with no problems. ... Why am I getting this linking errors ... unless I do a 'make clean' first? ...
    (comp.unix.programmer)