Search code examples
c++ccompilationlinkerstatic-linking

How to provide functions that cannot be found at linking?


When I try to compile my app, I get two errors:

$ g++ -static -emit-swf -o CloudClient.swf -I../boost/boost_libraries/install-dir/include -I../ffm peg-1.0/bin/include -L../boost/boost_libraries/install-dir/lib -L../ffmpeg-1.0/bin/lib timer.o audio_encoder.o audio_generator.o video_encoder.o video_generator_rainbow.o sim ple_synchronizer.o multiplexer.o transmitter.o graph_runner.o cloud_client.o -lswscale -lavformat -lavcodec -lavutil -lboost_system -lboost_date_time -lboost_thread -pthread -lm

../ffmpeg-1.0/bin/lib/libswscale.a: error: undefined reference to 'exp'
../ffmpeg-1.0/bin/lib/libavcodec.a: error: undefined reference to 'log'
collect2: ld returned 1 exit status

If log and exp are my problem and if anywhere I put -lm it does not help I wonder how to literally create my own stubs instead exp and log and link my libs with them? ....


Solution

  • You would implement them in a C file (than gets compiled by a C compiler, not a C++ compiler), or in a C++ file and give then extern "C" linkage. For example:

    extern "C" double log(double x)
    {
        // ...
    }
    

    Obviously it would be better for you to solve the link problem though. You shouldn't have to provide your own versions of standard C library routines.