I’m trying to convert the build mechanism of ccextractor (Open source closed caption extractor) from custom Makefile to Autotools generated Makefile.
Current Makefile looks like this:
SHELL = /bin/sh CC = gcc SYS := $(shell gcc -dumpmachine) CFLAGS = -O3 -std=gnu99 -s INCLUDE = -Isrc/gpacmp4/ -Isrc/libpng -Isrc/lib_hash -Isrc/protobuf-c -Isrc/zlib -Isrc/lib_ccx -Isrc/. INCLUDE += -Isrc/zvbi -Isrc/utf8proc ALL_FLAGS = -Wno-write-strings -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT LDFLAGS = -lm ifneq (, $(findstring linux, $(SYS))) CFLAGS +=-DGPAC_CONFIG_LINUX endif TARGET = ccextractor OBJS_DIR = objs VPATH = src:src/gpacmp4:src/libpng:src/zlib:src/lib_ccx:src/zvbi:src/lib_hash:src/utf8proc:src/protobuf-c SRCS_DIR = src SRCS_C = $(wildcard $(SRCS_DIR)/*.c) OBJS = $(SRCS_C:$(SRCS_DIR)/%.c=$(OBJS_DIR)/%.o) SRCS_CCX_DIR = $(SRCS_DIR)/lib_ccx SRCS_CCX = $(wildcard $(SRCS_CCX_DIR)/*.c) OBJS_CCX = $(SRCS_CCX:$(SRCS_CCX_DIR)/%.c=$(OBJS_DIR)/%.o) SRCS_PNG_DIR = $(SRCS_DIR)/libpng SRCS_PNG = $(wildcard $(SRCS_PNG_DIR)/*.c) OBJS_PNG = $(SRCS_PNG:$(SRCS_PNG_DIR)/%.c=$(OBJS_DIR)/%.o) SRCS_ZVBI_DIR = $(SRCS_DIR)/zvbi SRCS_ZVBI = $(wildcard $(SRCS_ZVBI_DIR)/*.c) OBJS_ZVBI = $(SRCS_ZVBI:$(SRCS_ZVBI_DIR)/%.c=$(OBJS_DIR)/%.o) SRCS_GPACMP4_DIR = $(SRCS_DIR)/gpacmp4 SRCS_GPACMP4_C = $(wildcard $(SRCS_GPACMP4_DIR)/*.c) SRCS_GPACMP4_CPP = $(wildcard $(SRCS_GPACMP4_DIR)/*.cpp) OBJS_GPACMP4 = $(SRCS_GPACMP4_C:$(SRCS_GPACMP4_DIR)/%.c=$(OBJS_DIR)/%.o) $(SRCS_GPACMP4_CPP:$(SRCS_GPACMP4_DIR)/%.cpp=$(OBJS_DIR)/%.o) SRCS_ZLIB_DIR = $(SRCS_DIR)/zlib SRCS_ZLIB = $(wildcard $(SRCS_ZLIB_DIR)/*.c) OBJS_ZLIB = $(SRCS_ZLIB:$(SRCS_ZLIB_DIR)/%.c=$(OBJS_DIR)/%.o) SRCS_HASH_DIR = $(SRCS_DIR)/lib_hash SRCS_HASH = $(wildcard $(SRCS_HASH_DIR)/*.c) OBJS_HASH = $(SRCS_HASH:$(SRCS_HASH_DIR)/%.c=$(OBJS_DIR)/%.o) SRCS_UTF8_DIR = $(SRCS_DIR)/utf8proc SRCS_UTF8 = $(SRCS_UTF8_DIR)/utf8proc.c OBJS_UTF8 = $(SRCS_UTF8:$(SRCS_UTF8_DIR)/%.c=$(OBJS_DIR)/%.o) INSTLALL = cp -f -p INSTLALL_PROGRAM = $(INSTLALL) DESTDIR = /usr/bin ifeq ($(ENABLE_HARDSUBX),yes) ENABLE_OCR=yes CFLAGS+=-DENABLE_HARDSUBX CFLAGS+= $(shell pkg-config --cflags libavcodec) CFLAGS+= $(shell pkg-config --cflags libavformat) CFLAGS+= $(shell pkg-config --cflags libavutil) CFLAGS+= $(shell pkg-config --cflags libswscale) AV_LDFLAGS+= $(shell pkg-config --libs libavcodec ) AV_LDFLAGS+= $(shell pkg-config --libs libavformat ) AV_LDFLAGS+= $(shell pkg-config --libs libavutil ) AV_LDFLAGS+= $(shell pkg-config --libs libswscale ) ifeq ($(AV_LDFLAGS),$(EMPTY)) $(error **ERROR** "libav not found") else $(info "libav found") endif LDFLAGS+= $(AV_LDFLAGS) endif ifeq ($(ENABLE_OCR),yes) CFLAGS+=-DENABLE_OCR -DPNG_NO_CONFIG_H LEPT_LDFLAGS+= $(shell pkg-config --libs lept) ifneq ($(shell pkg-config --exists tesseract), $(EMPTY)) TESS_LDFLAGS+= $(shell pkg-config --libs tesseract) TESS_CFLAGS+= $(shell pkg-config --cflags tesseract) else #fix for raspberry pi not having a pkgconfig file for tesseract ifneq ($(wildcard /usr/include/tesseract/*),$(EMPTY)) TESS_LDFLAGS+= -ltesseract TESS_CFLAGS+= -I/usr/include/tesseract endif endif #error checking of library are there or not ifeq ($(TESS_LDFLAGS),$(EMPTY)) $(error **ERROR** "tesseract not found") else #TODO print the version of library found $(info "tesseract found") endif ifeq ($(LEPT_LDFLAGS),$(EMPTY)) $(error **ERROR** "leptonica not found") else #TODO print the version of library found $(info "Leptonica found") endif CFLAGS += $(TESS_CFLAGS) CFLAGS += $(shell pkg-config --cflags lept) LDFLAGS += $(TESS_LDFLAGS) LDFLAGS += $(LEPT_LDFLAGS) endif ifeq ($(ENABLE_FFMPEG),yes) CFLAGS+=-DENABLE_FFMPEG CFLAGS+= $(shell pkg-config --cflags libavcodec) CFLAGS+= $(shell pkg-config --cflags libavformat) CFLAGS+= $(shell pkg-config --cflags libavutil) LDFLAGS+= $(shell pkg-config --libs libavcodec ) LDFLAGS+= $(shell pkg-config --libs libavformat ) LDFLAGS+= $(shell pkg-config --libs libavutil ) endif .PHONY: all all: pre-build objs_dir $(TARGET) .PHONY: objs_dir objs_dir: mkdir -p $(OBJS_DIR) $(TARGET): $(OBJS) $(OBJS_PNG) $(OBJS_GPACMP4) $(OBJS_ZVBI) $(OBJS_ZLIB) $(OBJS_HASH) $(OBJS_CCX) $(OBJS_UTF8) $(CC) $(ALL_FLAGS) $(CFLAGS) $(OBJS) $(OBJS_CCX) $(OBJS_PNG) $(OBJS_ZVBI) $(OBJS_GPACMP4) $(OBJS_ZLIB) $(OBJS_HASH) $(OBJS_UTF8) $(LDFLAGS) -o $@ $(OBJS_DIR)/%.o: %.c $(CC) -c $(ALL_FLAGS) $(INCLUDE) $(CFLAGS) $< -o $@ $(OBJS_DIR)/%.o: %.cpp $(CC) -c $(ALL_FLAGS) $(INCLUDE) $(CFLAGS) $< -o $@ -Isrc/gpacmp4 $(OBJS_DIR)/ccextractor.o: ccextractor.c $(CC) -c $(ALL_FLAGS) $(INCLUDE) $(CFLAGS) -O0 $< -o $@ .PHONY: clean clean: rm -rf $(TARGET) 2>/dev/null || true rm -rf $(OBJS_CCX) $(OBJS_PNG) $(OBJS_ZLIB) $(OBJS_GPACMP4) $(OBJS_HASH) $(OBJS_UTF8) $(OBJS) 2>/dev/null || true rm -rdf $(OBJS_DIR) 2>/dev/null || true rm -rf .depend 2>/dev/null || true .PHONY: install install: $(TARGET) $(INSTLALL_PROGRAM) $(TARGET) $(DESTDIR) .PHONY: uninstall uninstall: rm -iv $(DESTDIR)/$(TARGET) .PHONY: depend dep depend dep: $(CC) $(CFLAGS) $(INCLUDE) -E -MM $(SRCS_C) $(SRCS_PNG) $(SRCS_ZVBI) $(SRCS_ZLIB) $(SRCS_HASH) $(SRCS_UTF8) $(SRCS_CCX) $(SRCS_GPACMP4_C) $(SRCS_GPACMP4_CPP) | sed 's/^[a-zA-Z_0-9]*.o/$(OBJS_DIR)/&/' > .depend .PHONY: pre-build pre-build: ./pre-build.sh -include .depend
Building through above Makefile works fine. My Makefile.am looks like this:
bin_PROGRAMS = ccextractor ccextractor_SOURCES = **Removing common content of Makefile.am as below due to maximum character limit** AM_CPPFLAGS = -I src -I /usr/include/leptonica/ -I /usr/include/tesseract/ -I src/lib_ccx/ -I src/gpacmp4/ -I src/libpng/ -I src/zlib/ -I src/zvbi/ -I src/lib_hash/ -I src/protobuf-c/ -I src/utf8proc/ AM_CFLAGS = -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR AM_LDFLAGS = -lm -lz -ltesseract -llept
If I run make
after autoreconf -i
on above file, build fails with error:
/usr/bin/ld: src/gpacmp4/av_parsers.o: undefined reference to symbol 'trunc@@GLIBC_2.2.5' /lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
If I run ./configure
as ./configure LIBS="-lm -lz"
build fails with errors as:
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/gpacmp4/drm_sample.c:1358: undefined reference to `gf_isom_get_track_from_file' src/gpacmp4/drm_sample.o: In function `gf_isom_get_adobe_protection_info': /media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/gpacmp4/drm_sample.c:1378: undefined reference to `gf_isom_get_track_from_file' /media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/gpacmp4/drm_sample.c:1387: undefined reference to `IsMP4Description' src/gpacmp4/drm_sample.o: In function `gf_isom_cenc_is_pattern_mode': /media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/gpacmp4/drm_sample.c:1401: undefined reference to `gf_isom_get_track_from_file' src/gpacmp4/drm_sample.o: In function `gf_isom_ipmpx_remove_tool_list': /media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/gpacmp4/drm_sample.c:1421: undefined reference to `gf_odf_desc_del' collect2: error: ld returned 1 exit status
tree
in src
dir is:
. ├── ccextractor.c ├── CCExtractorConfig.h.in ├── ccextractor.o ├── CMakeLists.txt ├── gpacmp4 │ ├── avc_ext.c │ ├── avc_ext.o │ ├── avilib.c │ ├── avilib.o │ ├── av_parsers.c │ ├── drm_sample.o │ ├── error.c │ ├── error.o │ ├── gpac │ │ ├── avparse.h │ │ ├── base_coding.h │ │ ├── bitstream.h │ │ ├── config_file.h │ │ ├── configuration.h │ │ ├── constants.h │ │ ├── events_constants.h │ │ ├── ietf.h │ │ ├── internal │ │ │ ├── avilib.h │ │ │ ├── isomedia_dev.h │ │ │ ├── media_dev.h │ │ │ ├── odf_dev.h │ │ │ ├── odf_parse_common.h │ │ │ └── ogg.h │ │ ├── isomedia.h │ │ ├── list.h │ │ ├── math.h │ │ ├── media_tools.h │ │ ├── mpeg4_odf.h │ │ ├── network.h │ │ ├── revision.h │ │ ├── setup.h │ │ ├── sync_layer.h │ │ ├── tools.h │ │ ├── utf.h │ │ └── version.h │ ├── gpac_ogg.c │ ├── hinting.c │ ├── ipmpx_code.c │ ├── ipmpx_parse.c │ ├── isom_intern.c │ ├── isom_read.c │ ├── isom_store.c │ ├── isom_write.c │ ├── list.c │ ├── math.c │ ├── media.c │ ├── media_odf.c │ ├── meta.c │ ├── movie_fragments.c │ ├── mp4.c │ ├── odf_code.c │ ├── odf_codec.c │ ├── odf_command.c │ ├── os_config_init.c │ ├── os_divers.c │ ├── os_file.c │ ├── qos.c │ ├── ReadMe.txt │ ├── sample_descs.c │ ├── slc.c │ ├── stbl_read.c │ ├── stbl_write.c │ ├── track.c │ ├── tx3g.c │ ├── url.c │ └── utf.c ├── lib_ccx │ ├── activity.c │ ├── activity.h │ ├── asf_constants.h │ ├── asf_functions.c │ ├── avc_functions.c │ ├── avc_functions.h │ ├── bitstream.h │ ├── cc_bitstream.c │ ├── ccfont2.xbm │ ├── ccx_common_char_encoding.c │ ├── ccx_common_char_encoding.h │ ├── ccx_decoders_708.h │ ├── ccx_decoders_708_output.c │ ├── ccx_encoders_xds.h │ ├── ccx_gxf.c │ ├── ccx_gxf.h │ ├── ccx_mp4.h │ ├── dvd_subtitle_decoder.c │ ├── utility.h │ ├── wtv_constants.h │ └── wtv_functions.c ├── lib_hash │ ├── README │ ├── sha2.c │ └── sha2.h ├── libpng │ ├── png.c │ ├── pngconf.h │ ├── pngdebug.h │ ├── pngerror.c │ ├── pngget.c | | ├── protobuf-c │ ├── protobuf-c.c │ └── protobuf-c.h ├── utf8proc │ ├── utf8proc.c │ ├── utf8proc_data.c │ └── utf8proc.h ├── win_iconv │ ├── iconv.h │ └── win_iconv.c ├── win_spec_incld │ ├── dirent.h │ ├── inttypes.h │ └── stdint.h ├── zlib │ ├── adler32.c │ ├── compress.c │ ├── crc32.c │ ├── crc32.h │ ├── deflate.c │ ├── deflate.h │ ├── gzclose.c │ ├── gzguts.h │ ├── zutil.c │ └── zutil.h └── zvbi ├── bcd.h ├── bit_slicer.c ├── bit_slicer.h ├── decoder.c ├── macros.h ├── misc.h ├── raw_decoder.c ├── raw_decoder.h ├── sampling_par.c ├── sampling_par.h ├── sliced.h └── zvbi_decoder.h **Stripped some filenames (not directory) due to max character limit**
And also, all includes are done with full path in sub directories of src
, like for a file in gpacmp4
directory, #include <gpac/avparse.h>
. All but the main ccextractor.c
file, for which all the -I flags
are provided.
To refer ccextractor original code: https://github.com/CCExtractor/ccextractor
The original Makefile
will be in linux
directory.
PS: Currently I’m trying to get the ccextractor build all the checks will be introduced later. For simplified mechanism ccextractor/linux/build
is useful to refer.
Even the slightest help is appreciated.
UPDATE: (courtesy of @MadScientist)
I updated Makefile.am
as:
AUTOMAKE_OPTIONS = foreign bin_PROGRAMS = ccextractor ccextractor_SOURCES = src/ccextractor.c src/gpacmp4/avc_ext.c src/gpacmp4/avilib.c src/gpacmp4/av_parsers.c src/gpacmp4/base_encoding.c src/gpacmp4/bitstream.c src/gpacmp4/box_code_3gpp.c src/gpacmp4/box_code_adobe.c src/gpacmp4/box_code_apple.c src/gpacmp4/box_code_base.c src/gpacmp4/box_code_drm.c src/gpacmp4/box_code_meta.c src/gpacmp4/box_funcs.c src/gpacmp4/configfile.c src/gpacmp4/data_map.c src/gpacmp4/desc_private.c src/gpacmp4/descriptors.c src/gpacmp4/drm_sample.c src/gpacmp4/error.c src/gpacmp4/gpac/avparse.h src/gpacmp4/gpac/base_coding.h src/gpacmp4/gpac/bitstream.h src/gpacmp4/gpac/config_file.h src/gpacmp4/gpac/configuration.h src/gpacmp4/gpac/constants.h src/gpacmp4/gpac/events_constants.h src/gpacmp4/gpac/ietf.h src/gpacmp4/gpac/internal src/gpacmp4/gpac/internal/avilib.h src/gpacmp4/gpac/internal/isomedia_dev.h src/gpacmp4/gpac/internal/media_dev.h src/gpacmp4/gpac/internal/odf_dev.h src/gpacmp4/gpac/internal/odf_parse_common.h src/gpacmp4/gpac/internal/ogg.h src/gpacmp4/gpac/isomedia.h src/gpacmp4/gpac/list.h src/gpacmp4/gpac/math.h src/gpacmp4/gpac/media_tools.h src/gpacmp4/gpac/mpeg4_odf.h src/gpacmp4/gpac/network.h src/gpacmp4/gpac/revision.h src/gpacmp4/gpac/setup.h src/gpacmp4/gpac/sync_layer.h src/gpacmp4/gpac/tools.h src/gpacmp4/gpac/utf.h src/gpacmp4/gpac/version.h src/gpacmp4/gpac_ogg.c src/gpacmp4/hinting.c src/gpacmp4/ipmpx_code.c src/gpacmp4/ipmpx_parse.c src/gpacmp4/isom_intern.c src/gpacmp4/isom_read.c src/gpacmp4/isom_store.c src/gpacmp4/isom_write.c src/gpacmp4/list.c src/gpacmp4/math.c src/gpacmp4/media.c src/gpacmp4/media_odf.c src/gpacmp4/meta.c src/gpacmp4/movie_fragments.c src/gpacmp4/mp4.c src/gpacmp4/odf_code.c src/gpacmp4/odf_codec.c src/gpacmp4/odf_command.c src/gpacmp4/os_config_init.c src/gpacmp4/os_divers.c src/gpacmp4/os_file.c src/gpacmp4/qos.c src/gpacmp4/ReadMe.txt src/gpacmp4/sample_descs.c src/gpacmp4/slc.c src/gpacmp4/stbl_read.c src/gpacmp4/stbl_write.c src/gpacmp4/track.c src/gpacmp4/tx3g.c src/gpacmp4/url.c src/gpacmp4/utf.c src/lib_ccx/activity.c src/lib_ccx/activity.h src/lib_ccx/asf_constants.h src/lib_ccx/asf_functions.c src/lib_ccx/avc_functions.c src/lib_ccx/avc_functions.h src/lib_ccx/bitstream.h src/lib_ccx/cc_bitstream.c src/lib_ccx/ccx_common_char_encoding.c src/lib_ccx/ccx_common_char_encoding.h src/lib_ccx/ccx_common_common.c src/lib_ccx/ccx_common_common.h src/lib_ccx/ccx_common_constants.c src/lib_ccx/ccx_common_constants.h src/lib_ccx/ccx_common_option.c src/lib_ccx/ccx_common_option.h src/lib_ccx/ccx_common_platform.h src/lib_ccx/ccx_common_structs.h src/lib_ccx/ccx_common_timing.c src/lib_ccx/ccx_common_timing.h src/lib_ccx/ccx_decoders_608.c src/lib_ccx/ccx_decoders_608.h src/lib_ccx/ccx_decoders_708.c src/lib_ccx/ccx_decoders_708_encoding.c src/lib_ccx/ccx_decoders_708_encoding.h src/lib_ccx/ccx_decoders_708.h src/lib_ccx/ccx_decoders_708_output.c src/lib_ccx/ccx_decoders_708_output.h src/lib_ccx/ccx_decoders_common.c src/lib_ccx/ccx_decoders_common.h src/lib_ccx/ccx_decoders_isdb.c src/lib_ccx/ccx_decoders_isdb.h src/lib_ccx/ccx_decoders_structs.h src/lib_ccx/ccx_decoders_vbi.c src/lib_ccx/ccx_decoders_vbi.h src/lib_ccx/ccx_decoders_xds.c src/lib_ccx/ccx_decoders_xds.h src/lib_ccx/ccx_demuxer.c src/lib_ccx/ccx_demuxer.h src/lib_ccx/ccx_dtvcc.c src/lib_ccx/ccx_dtvcc.h src/lib_ccx/ccx_encoders_common.c src/lib_ccx/ccx_encoders_common.h src/lib_ccx/ccx_encoders_curl.c src/lib_ccx/ccx_encoders_g608.c src/lib_ccx/ccx_encoders_helpers.c src/lib_ccx/ccx_encoders_helpers.h src/lib_ccx/ccx_encoders_sami.c src/lib_ccx/ccx_encoders_smptett.c src/lib_ccx/ccx_encoders_splitbysentence.c src/lib_ccx/ccx_encoders_spupng.c src/lib_ccx/ccx_encoders_spupng.h src/lib_ccx/ccx_encoders_srt.c src/lib_ccx/ccx_encoders_ssa.c src/lib_ccx/ccx_encoders_structs.h src/lib_ccx/ccx_encoders_transcript.c src/lib_ccx/ccx_encoders_webvtt.c src/lib_ccx/ccx_encoders_xds.c src/lib_ccx/ccx_encoders_xds.h src/lib_ccx/ccx_gxf.c src/lib_ccx/ccx_gxf.h src/lib_ccx/ccx_mp4.h src/lib_ccx/ccx_share.c src/lib_ccx/ccx_share.h src/lib_ccx/ccx_sub_entry_message.pb-c.c src/lib_ccx/ccx_sub_entry_message.pb-c.h src/lib_ccx/CMakeLists.txt src/lib_ccx/compile_info.h src/lib_ccx/compile_info_real.h src/lib_ccx/configuration.c src/lib_ccx/configuration.h src/lib_ccx/disable_warnings.h src/lib_ccx/dvb_subtitle_decoder.c src/lib_ccx/dvb_subtitle_decoder.h src/lib_ccx/dvd_subtitle_decoder.c src/lib_ccx/dvd_subtitle_decoder.h src/lib_ccx/es_functions.c src/lib_ccx/es_userdata.c src/lib_ccx/ffmpeg_intgr.c src/lib_ccx/ffmpeg_intgr.h src/lib_ccx/file_buffer.h src/lib_ccx/file_functions.c src/lib_ccx/general_loop.c src/lib_ccx/hamming.h src/lib_ccx/hardsubx.c src/lib_ccx/hardsubx_classifier.c src/lib_ccx/hardsubx_decoder.c src/lib_ccx/hardsubx.h src/lib_ccx/hardsubx_imgops.c src/lib_ccx/hardsubx_utility.c src/lib_ccx/lib_ccx.c src/lib_ccx/lib_ccx.h src/lib_ccx/list.h src/lib_ccx/matroska.c src/lib_ccx/matroska.h src/lib_ccx/myth.c src/lib_ccx/networking.c src/lib_ccx/networking.h src/lib_ccx/ocr.c src/lib_ccx/ocr.h src/lib_ccx/output.c src/lib_ccx/params.c src/lib_ccx/params_dump.c src/lib_ccx/sequencing.c src/lib_ccx/spupng_encoder.c src/lib_ccx/spupng_encoder.h src/lib_ccx/stdintmsc.h src/lib_ccx/stream_functions.c src/lib_ccx/teletext.h src/lib_ccx/telxcc.c src/lib_ccx/ts_functions.c src/lib_ccx/ts_functions.h src/lib_ccx/ts_info.c src/lib_ccx/ts_tables.c src/lib_ccx/ts_tables_epg.c src/lib_ccx/utility.c src/lib_ccx/utility.h src/lib_ccx/wtv_constants.h src/lib_ccx/wtv_functions.c src/lib_hash/sha2.c src/lib_hash/sha2.h src/libpng/png.c src/libpng/pngconf.h src/libpng/pngdebug.h src/libpng/pngerror.c src/libpng/pngget.c src/libpng/png.h src/libpng/pnginfo.h src/libpng/pnglibconf.h src/libpng/pngmem.c src/libpng/pngpread.c src/libpng/pngpriv.h src/libpng/pngread.c src/libpng/pngrio.c src/libpng/pngrtran.c src/libpng/pngrutil.c src/libpng/pngset.c src/libpng/pngstruct.h src/libpng/pngtrans.c src/libpng/pngwio.c src/libpng/pngwrite.c src/libpng/pngwtran.c src/libpng/pngwutil.c src/protobuf-c/protobuf-c.c src/protobuf-c/protobuf-c.h src/utf8proc/utf8proc.c src/utf8proc/utf8proc_data.c src/utf8proc/utf8proc.h src/win_iconv/iconv.h src/win_iconv/win_iconv.c src/win_spec_incld/dirent.h src/win_spec_incld/inttypes.h src/win_spec_incld/stdint.h src/zlib/adler32.c src/zlib/compress.c src/zlib/crc32.c src/zlib/crc32.h src/zlib/deflate.c src/zlib/deflate.h src/zlib/gzclose.c src/zlib/gzguts.h src/zlib/gzlib.c src/zlib/gzread.c src/zlib/gzwrite.c src/zlib/infback.c src/zlib/inffast.c src/zlib/inffast.h src/zlib/inffixed.h src/zlib/inflate.c src/zlib/inflate.h src/zlib/inftrees.c src/zlib/inftrees.h src/zlib/trees.c src/zlib/trees.h src/zlib/uncompr.c src/zlib/zconf.h src/zlib/zlib.h src/zlib/zutil.c src/zlib/zutil.h src/zvbi/bcd.h src/zvbi/bit_slicer.c src/zvbi/bit_slicer.h src/zvbi/decoder.c src/zvbi/macros.h src/zvbi/misc.h src/zvbi/raw_decoder.c src/zvbi/raw_decoder.h src/zvbi/sampling_par.c src/zvbi/sampling_par.h src/zvbi/sliced.h src/zvbi/zvbi_decoder.h ccextractor_CFLAGS =-std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR ccextractor_CPPFLAGS =-I /usr/include/leptonica/ -I /usr/include/tesseract/ -I src/lib_ccx/ -I src/gpacmp4/ -I src/libpng/ -I src/zlib/ -I src/zvbi/ -I src/lib_hash/ -I src/protobuf-c/ -I src/utf8proc/ ccextractor_LDADD =-lm -ltesseract -llept ccextractor_LDFLAGS=-zmuldefs
The build
script which builds “ccextractor” perfectly fine is:
#!/bin/bash BLD_FLAGS="-std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR" BLD_INCLUDE="-Isrc -I /usr/include/leptonica/ -I /usr/include/tesseract/ -Isrc/lib_ccx/ -Isrc/gpacmp4/ -Isrc/libpng/ -Isrc/zlib/ -Isrc/zvbi -Isrc/lib_hash -Isrc/protobuf-c -Isrc/utf8proc" SRC_LIBPNG="$(find src/libpng/ -name '*.c')" SRC_ZLIB="$(find src/zlib/ -name '*.c')" SRC_ZVBI="$(find src/zvbi/ -name '*.c')" SRC_CCX="$(find src/lib_ccx/ -name '*.c')" SRC_GPAC="$(find src/gpacmp4/ -name '*.c')" SRC_HASH="$(find src/lib_hash/ -name '*.c')" SRC_PROTOBUF="$(find src/protobuf-c/ -name '*.c')" SRC_UTF8PROC="src/utf8proc/utf8proc.c" BLD_SOURCES="src/ccextractor.c $SRC_CCX $SRC_GPAC $SRC_ZLIB $SRC_ZVBI $SRC_LIBPNG $SRC_HASH $SRC_PROTOBUF $SRC_UTF8PROC" BLD_LINKER="-lm -zmuldefs -l tesseract -l lept" **Stripped a call for a script which checks the git commit (nothing that'd interfere with build** out=$((LC_ALL=C gcc $BLD_FLAGS $BLD_INCLUDE -o ccextractor $BLD_SOURCES $BLD_LINKER) 2>&1) res=$? if [[ $out == *"gcc: command not found"* ]] then echo "Error: please install gcc"; exit 1 fi if [[ $out == *"curl.h: No such file or directory"* ]] then echo "Error: please install curl development library (libcurl4-gnutls-dev for Debian/Ubuntu)"; exit 2 fi if [[ $out == *"capi.h: No such file or directory"* ]] then echo "Error: please install tesseract development library (tesseract-ocr-dev for Debian/Ubuntu)"; exit 3 fi if [[ $out == *"allheaders.h: No such file or directory"* ]] then echo "Error: please install leptonica development library (libleptonica-dev for Debian/Ubuntu)"; exit 4 fi if [[ $res -ne 0 ]] # Unknown error then echo "Compiled with errors" >&2 echo "$out" exit 5 fi echo "Compilation successful";
Here are some initial statements which make
invokes:
gcc -DHAVE_CONFIG_H -I. -I /usr/include/leptonica/ -I /usr/include/tesseract/ -I src/lib_ccx/ -I src/gpacmp4/ -I src/libpng/ -I src/zlib/ -I src/zvbi/ -I src/lib_hash/ -I src/protobuf-c/ -I src/utf8proc/ -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR -g -O2 -MT src/ccextractor-ccextractor.o -MD -MP -MF src/.deps/ccextractor-ccextractor.Tpo -c -o src/ccextractor-ccextractor.o `test -f 'src/ccextractor.c' || echo './'`src/ccextractor.c mv -f src/.deps/ccextractor-ccextractor.Tpo src/.deps/ccextractor-ccextractor.Po gcc -DHAVE_CONFIG_H -I. -I /usr/include/leptonica/ -I /usr/include/tesseract/ -I src/lib_ccx/ -I src/gpacmp4/ -I src/libpng/ -I src/zlib/ -I src/zvbi/ -I src/lib_hash/ -I src/protobuf-c/ -I src/utf8proc/ -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR -g -O2 -MT src/gpacmp4/ccextractor-avc_ext.o -MD -MP -MF src/gpacmp4/.deps/ccextractor-avc_ext.Tpo -c -o src/gpacmp4/ccextractor-avc_ext.o `test -f 'src/gpacmp4/avc_ext.c' || echo './'`src/gpacmp4/avc_ext.c mv -f src/gpacmp4/.deps/ccextractor-avc_ext.Tpo src/gpacmp4/.deps/ccextractor-avc_ext.Po gcc -DHAVE_CONFIG_H -I. -I /usr/include/leptonica/ -I /usr/include/tesseract/ -I src/lib_ccx/ -I src/gpacmp4/ -I src/libpng/ -I src/zlib/ -I src/zvbi/ -I src/lib_hash/ -I src/protobuf-c/ -I src/utf8proc/ -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR -g -O2 -MT src/gpacmp4/ccextractor-avilib.o -MD -MP -MF src/gpacmp4/.deps/ccextractor-avilib.Tpo -c -o src/gpacmp4/ccextractor-avilib.o `test -f 'src/gpacmp4/avilib.c' || echo './'`src/gpacmp4/avilib.c mv -f src/gpacmp4/.deps/ccextractor-avilib.Tpo src/gpacmp4/.deps/ccextractor-avilib.Po
Statement which make
invokes just before showing undefined reference errors:
gcc -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR -g -O2 -zmuldefs -o ccextractor src/ccextractor-ccextractor.o src/gpacmp4/ccextractor-avc_ext.o src/gpacmp4/ccextractor-avilib.o src/gpacmp4/ccextractor-av_parsers.o src/gpacmp4/ccextractor-base_encoding.o src/gpacmp4/ccextractor-bitstream.o src/gpacmp4/ccextractor-box_code_3gpp.o src/gpacmp4/ccextractor-box_code_adobe.o src/gpacmp4/ccextractor-box_code_apple.o src/gpacmp4/ccextractor-box_code_base.o src/gpacmp4/ccextractor-box_code_drm.o src/gpacmp4/ccextractor-box_code_meta.o src/gpacmp4/ccextractor-box_funcs.o src/gpacmp4/ccextractor-configfile.o src/gpacmp4/ccextractor-data_map.o src/gpacmp4/ccextractor-desc_private.o src/gpacmp4/ccextractor-descriptors.o src/gpacmp4/ccextractor-drm_sample.o src/gpacmp4/ccextractor-error.o -lm -ltesseract -llept /media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:32: undefined reference to `mprint' /media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:33: undefined reference to `change_filename_requested' src/ccextractor-ccextractor.o: In function `sigint_handler': /media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:47: undefined reference to `print_file_report' src/ccextractor-ccextractor.o: In function `print_end_msg': /media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:55: undefined reference to `mprint' /media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:56: undefined reference to `mprint' src/ccextractor-ccextractor.o: In function `main': /media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:68: undefined reference to `init_options' /media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:70: undefined reference to `parse_configuration' /media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:71: undefined reference to `parse_parameters'
PS: Sorry for the delay in update. Any help is appreciated.I tried many things including changing the path of the #include <path/to/header>
statements in code and then adding -I
statement in CFLAGS
but that didn’t help either. Almost all the undefined reference errors are from the functions declared in the headers residing in subdirectories of directories in source like, src/dir/subdir
the -I
flags are added only till src/dir/
and then the files in src/dir/
have statements like #include<subdir/filename.h>
.
PPS: I used grep -r "<Name_of_function_leading_to_error>" .
in src
to find out the declaration header.
Advertisement
Answer
You don’t show the line make invoked to link your code, which would be very useful.
However, you don’t want to put libraries into the LDLFLAGS
(or AM_LDLFAGS
) variable; that variable is for linker flags like -L
, etc. You should use LDADD
:
LDADD = -lm -lz -ltesseract -llept
If you look at the link line that make is generating you’ll see all these options coming BEFORE any of your object files on the link line; that’s not right. The GNU binutils ld is a single-pass linker, which means that the order of -l
flags is very important for proper linking.