【问题标题】:How to provide functions that cannot be found at linking?如何提供链接时找不到的功能?
【发布时间】:2012-10-25 00:26:48
【问题描述】:

当我尝试编译我的应用程序时,出现两个错误:

$ 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 多路复用器.o 发射器.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

如果logexp 是我的问题,如果我把-lm 放在任何地方,我想知道如何从字面上创建我自己的存根而不是explog 并将我的库与它们链接? ....

【问题讨论】:

  • 只创建具有匹配签名的空函数?
  • @JosephQuinsey:没关系。来自man gcc-pthread: Adds support for multithreading with the pthreads library. This option sets flags for both the preprocessor and linker.

标签: c++ c compilation linker static-linking


【解决方案1】:

您可以在 C 文件中实现它们(而不是由 C 编译器而不是 C++ 编译器编译),或者在 C++ 文件中实现它们,然后给出外部“C”链接。例如:

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

显然,解决链接问题对您来说会更好。您不必提供自己的标准 C 库例程版本。

【讨论】:

  • 能否获取库中使用了哪个函数重载?
  • @myWallJSON C++ 库提供了三个重载 (cplusplus.com/reference/clibrary/cmath/log)。但是,C 没有重载。它只有double 版本。我假设 ffmpeg 是用 C 编写的,因此您不必提供任何重载(即使您提供了,C 代码也无法使用它们;重载仅适用于 C++ 链接。您不能重载extern "C" 函数。)
猜你喜欢
  • 2020-06-27
  • 1970-01-01
  • 2023-02-17
  • 1970-01-01
  • 1970-01-01
  • 2022-01-14
  • 2011-03-19
  • 1970-01-01
  • 2020-04-10
相关资源
最近更新 更多