一、编译选项如下
test : all
$(CC) $(CXXFLAGS) -I/DecoderFFMPEGLive/ -o Test/$@.o -c Test/test.cpp
$(CC) $(CXXFLAGS) -o $@ Test/$@.o -L. -lDecoderFFMPEGLive -lpthread
报错误:/usr/bin/ld: cannot open output file test: Is a directory
是因为我想生成test的执行文件,但是当前目录有一个Test文件夹,导致报错,将-o $@修改成-o $@demo(任意字符都可)
二、修改一之后,报错误
/usr/bin/ld: cannot find -lDecoderFFMPEGLive
编译知识太差导致我在这个问题浪费了好多时间,是因为我生成的库名字是libDecoderFFMPEGLive.so.1.0.0.7,我以为这样也能识别到......,想了好久,最后面突然开悟,将libDecoderFFMPEGLive.so.1.0.0.7重命名为libDecoderFFMPEGLive.so解决问题,当然也可以加软链接
三、
g++ -g -Wall -O3 -I/home/lis/code/DecoderFFMPEGLive/DecoderFFMPEGLive -I./comlib/ffmpeg/include -I./comlib/boost_1_71_0/include -I./comlib/XDevToolbox_release/include -std=c++11 -fPIC -fvisibility=hidden -o testdemo Test/test.o -lDecoderFFMPEGLive -L. -lpthread
./libDecoderFFMPEGLive.so: undefined reference to `x264_param_default'
./libDecoderFFMPEGLive.so: undefined reference to `x264_param_apply_profile'
./libDecoderFFMPEGLive.so: undefined reference to `x264_encoder_headers'
./libDecoderFFMPEGLive.so: undefined reference to `x264_encoder_encode'
./libDecoderFFMPEGLive.so: undefined reference to `avpriv_codec2_mode_bit_rate'
./libDecoderFFMPEGLive.so: undefined reference to `x264_encoder_reconfig'
./libDecoderFFMPEGLive.so: undefined reference to `x264_param_apply_fastfirstpass'
./libDecoderFFMPEGLive.so: undefined reference to `x264_encoder_delayed_frames'
./libDecoderFFMPEGLive.so: undefined reference to `x264_param_parse'
./libDecoderFFMPEGLive.so: undefined reference to `x264_levels'
./libDecoderFFMPEGLive.so: undefined reference to `x264_picture_init'
./libDecoderFFMPEGLive.so: undefined reference to `x264_encoder_close'
./libDecoderFFMPEGLive.so: undefined reference to `av_bitstream_filter_filter'
./libDecoderFFMPEGLive.so: undefined reference to `avpriv_codec2_mode_frame_size'
./libDecoderFFMPEGLive.so: undefined reference to `x264_param_default_preset'
./libDecoderFFMPEGLive.so: undefined reference to `x264_encoder_open_164'
./libDecoderFFMPEGLive.so: undefined reference to `avpriv_codec2_mode_block_align'
./libDecoderFFMPEGLive.so: undefined reference to `av_adts_header_parse'
使用nm命令查找动态库,发现未定义此函数,需要找libDecoderFFMPEGLive.so的问题
排查发现是libDecoderFFMPEGLive.so没有包含-lx264选项,加上即解决。
四、下面的函数都是在libavcodec中的,libDecoderFFMPEGLive.so明明加了-lavcodec选项,还是U(未定义),好奇怪
最后是在编译可执行程序时再加了-lavcodec才编译过(这里还是没理清楚为什么这样)
$(CC) $(CXXFLAGS) -o $@ Test/$@.o -L. -lDecoderFFMPEGLive -L$(FFMPEG_DIR)/lib -lavcodec -lpthread