代码之家  ›  专栏  ›  技术社区  ›  Hadi Rasekh

在另一个项目中使用libx264时出现未定义的引用错误

  •  1
  • Hadi Rasekh  · 技术社区  · 10 年前

    当我在另一个项目中使用x264 DLL时,在创建该项目时会报告“未定义的引用错误”!

    这是我的(example_exe.cpp)代码:

    #include <stdio.h>
    #include <stdint.h>
    #include <inttypes.h>
    
    #define X264_API_IMPORTS
    #include "x264.h"
    
    
    int main(void)
    {
        x264_param_t *t;
        x264_encoder_open(t);
        return 0;
    }
    

    这就是我编译和制作代码的方式:

    g++ -c example_exe.cpp
    g++ -o example_exe.exe example_exe.o -L. -llibx264-142
    

    我得到了以下错误:

    example_exe.o:example_exe.cpp:(.text+0x22): undefined reference to `x264_encoder_open_142(x264_param_t*)`
    
    1 回复  |  直到 10 年前
        1
  •  3
  •   nobody555    10 年前

    在编译C++(而不是C)时,需要使用外部“C”{…}作为x264.h标头,即。

    extern "C" {
    #include "x264.h"
    }