This question already has an answer here:
errors when compiling c code with ffmpeg library
(1 answer)
Closed 6 years ago.
After updating my ubuntu OS from 14.04 to 16.04, I installed the ffmpeg library using the following configurations:
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
--prefix="$HOME/ffmpeg_build" \
--pkg-config-flags="--static" \
--extra-cflags="-I$HOME/ffmpeg_build/include" \
--extra-ldflags="-L$HOME/ffmpeg_build/lib" \
--bindir="$HOME/bin" \
--enable-gpl \
--enable-libass \
--enable-libfdk-aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopus \
--enable-libtheora \
--enable-libvorbis \
--enable-libvpx \
--enable-libx264 \
--enable-nonfree
PATH="$HOME/bin:$PATH" make
make install
It seemed to me the installation process was ok. After that, I tried to compile my own C source code with the following Makefile:
EDITTED(adding -lva-drm -lva-x11 at line 10)
FFMPEG_LIBS= libavdevice \
libavformat \
libavfilter \
libavcodec \
libswresample \
libswscale \
libavutil \
TARGET = video_analysis
LIBS = -lva -lX11 -lvdpau -lm -lva-drm -lva-x11
CC = gcc
CFLAGS += -O2 -g -O0
CFLAGS := $(shell pkg-config --cflags $(FFMPEG_LIBS)) $(CFLAGS)
LDLIBS := $(shell pkg-config --libs $(FFMPEG_LIBS)) $(LDLIBS)
.PHONY: default all clean
default: $(TARGET)
all: default
OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
HEADERS = $(wildcard *.h)
%.o: %.c $(HEADERS)
$(CC) $(CFLAGS) -c $< -o $#
.PRECIOUS: $(TARGET) $(OBJECTS)
$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) $(LDLIBS) $(LIBS) -o $#
clean:
-rm -f *.o
-rm -f $(TARGET)
However, my compiler complained the following errors:
/root/ffmpeg_build/lib/libavutil.a(hwcontext_vaapi.o): In function `vaapi_device_create':
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:896: undefined reference to `vaGetDisplay'
/home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:917: undefined reference to `vaGetDisplayDRM'
collect2: error: ld returned 1 exit status
Makefile:30: recipe for target 'video_analysis' failed
make: *** [video_analysis] Error 1
My question is: in which library do 'vaGetDisplay' and `vaGetDisplayDRM' exist? It's for sure that libva functions properly. I have no clue how to fix the bugs...Thank you in advance!
I got the exact same problem when I was trying to compile the latest ffmpeg source code examples. (2016-08-25)
When I have done compiling ffmpeg source, (all dependencies good), then I go to dir:
~/ffmpeg_build/share/ffmpeg/examples$
do:
export PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig"
and as instructed as README:
make
I got the C files compiled to .o files but cannot get linked. Same error output as:
jack#jack-virtual-machine:~/ffmpeg_build/share/ffmpeg/examples$ make
cc avio_reading.o -pthread -L/home/jack/ffmpeg_build/lib -lavdevice -lavfilter -lpostproc -lavformat -lavcodec -lvdpau -lva-drm -lva-x11 -lva -lxcb-shm -lxcb-xfixes -lxcb-render -lxcb-shape -lxcb -lXau -lXdmcp -lSDL -lasound -lpulse-simple -lpulse -lX11 -lXext -lcaca -lx265 -lstdc++ -lrt -lx264 -ldl -lvpx -lpthread -lvorbisenc -lvorbis -ltheoraenc -ltheoradec -logg -lopus -lmp3lame -lfdk-aac -lass -lharfbuzz -lfontconfig -lfribidi -lexpat -lfreetype -lpng12 -llzma -lbz2 -lz -lswresample -lswscale -lavutil -lm -o avio_reading
/home/jack/ffmpeg_build/lib/libavutil.a(hwcontext_vaapi.o): In function `vaapi_device_free':
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vaapi.c:861: undefined reference to `XCloseDisplay'
/home/jack/ffmpeg_build/lib/libavutil.a(hwcontext_vaapi.o): In function `vaapi_device_create':
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vaapi.c:891: undefined reference to `XOpenDisplay'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vaapi.c:896: undefined reference to `vaGetDisplay'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vaapi.c:903: undefined reference to `XDisplayName'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vaapi.c:917: undefined reference to `vaGetDisplayDRM'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vaapi.c:893: undefined reference to `XDisplayName'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vaapi.c:898: undefined reference to `XDisplayName'
/home/jack/ffmpeg_build/lib/libavutil.a(hwcontext_vdpau.o): In function `vdpau_device_create':
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vdpau.c:431: undefined reference to `XOpenDisplay'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vdpau.c:437: undefined reference to `XDisplayString'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vdpau.c:439: undefined reference to `XDefaultScreen'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vdpau.c:439: undefined reference to `vdp_device_create_x11'
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vdpau.c:433: undefined reference to `XDisplayName'
/home/jack/ffmpeg_build/lib/libavutil.a(hwcontext_vdpau.o): In function `vdpau_device_free':
/home/jack/ffmpeg_source/FFmpeg/libavutil/hwcontext_vdpau.c:410: undefined reference to `XCloseDisplay'
collect2: error: ld returned 1 exit status
make: *** [avio_reading] Error 1
I checked your solution here and discovered that although ffmpeg team are using
pkg-config tool to config, but in the end it is a gcc command line to compile. (see the seconde line of code snippet above)
All the flags below shall be moved to the end of gcc command line just before the -o option:
-lX11 -lm -lvdpau -lva -lva-drm -lva-x11
So instead of compiling with the next command line:(the command is long, scroll to right to see full)
cc avio_reading.o -pthread -L/home/jack/ffmpeg_build/lib -lavdevice -lavfilter -lpostproc -lavformat -lavcodec -lvdpau -lva-drm -lva-x11 -lva -lxcb-shm -lxcb-xfixes -lxcb-render -lxcb-shape -lxcb -lXau -lXdmcp -lSDL -lasound -lpulse-simple -lpulse -lX11 -lXext -lcaca -lx265 -lstdc++ -lrt -lx264 -ldl -lvpx -lpthread -lvorbisenc -lvorbis -ltheoraenc -ltheoradec -logg -lopus -lmp3lame -lfdk-aac -lass -lharfbuzz -lfontconfig -lfribidi -lexpat -lfreetype -lpng12 -llzma -lbz2 -lz -lswresample -lswscale -lavutil -lm -o avio_reading
I move the flags to the right side end and compile with:(the command is long, scroll to right to see full)
cc avio_dir_cmd.o -pthread -L/home/jack/ffmpeg_build/lib -lavdevice -lavfilter -lpostproc -lavformat -lavcodec -lxcb-shm -lxcb-xfixes -lxcb-render -lxcb-shape -lxcb -lXau -lXdmcp -lSDL -lasound -lpulse-simple -lpulse -lXext -lcaca -lx265 -lstdc++ -lrt -lx264 -ldl -lvpx -lpthread -lvorbisenc -lvorbis -ltheoraenc -ltheoradec -logg -lopus -lmp3lame -lfdk-aac -lass -lharfbuzz -lfontconfig -lfribidi -lexpat -lfreetype -lpng12 -llzma -lbz2 -lz -lswresample -lswscale -lavutil -lX11 -lm -lvdpau -lva -lva-drm -lva-x11 -o avio_dir_cmd
And all the compile errors are gone~!
I think this is a common error when we compile other examples, or our own projects.
after adding -lva-drm and -lva-x11 into Makefile, my compiler complains no error any more :-)
Related
Now I cross-compile and link my code with both dynamic and static libraries, but the following error occurs: can't find lstdc + +(make error 1);
If I changed $LD to $CC, another issues occured: can't find -lpaho-mqtt3a(make error 2), what's going on?
change $(LD)
$(TARGET):$(OBJS)
$(LD) -o $(OUTPUT_DIR)/$(TARGET) $(OBJS) $(CFLAGS_OTHERS_LIB)
$(LIB_FOR_SRS) $(LINK_OPTION)
$(STRIP) $(OUTPUT_DIR)/$(TARGET)
to $(CC)
$(TARGET):$(OBJS)
$(CC) -o $(OUTPUT_DIR)/$(TARGET) $(OBJS) $(CFLAGS_OTHERS_LIB)
$(LIB_FOR_SRS) $(LINK_OPTION)
$(STRIP) $(OUTPUT_DIR)/$(TARGET)
I use these dynamic and static libraries to compile links:
paho-mqtt3a.so libjson-c.a libjson-c.la libsqlite3.so libsqlite3.la libsqlite3.a srs_librtmp.a
libssl.a libcrypto.a
Makefile :
COMPILE = aarch64-linux-gnu-
CC = $(COMPILE)gcc
STRIP = $(COMPILE)strip
LD = $(COMPILE)ld
COMPILE_OPTION = -Wall -Wcomment -Wformat -Wmissing-braces -Wswitch -Wuninitialized
\
-Wbad-function-cast -Waggregate-return -Wmultichar -Wsign-compare -
Wshadow
#COMPILE_OPTION_DEBUG = -gdwarf-2 -g
COMPILE_ALL_OPTION += $(COMPILE_OPTION) $(COMPILE_OPTION_DEBUG)
LINK_OPTION = -lpaho-mqtt3a -ljson-c -lsqlite3 -lm -lc -lpthread -ldl -lstdc++ -static
LIB_FOR_JSON = ./lib/json_lib/*
LIB_FOR_MQTT = ./lib/mqtt_lib/*
LIB_FOR_SQLITE3 = ./lib/sqlite3_lib/*
LIB_FOR_SRS = ./lib/srslibrtmp_lib/*
SRC_DIR = ./src
OUTPUT_DIR = ./output
SYS_LOCAL_LIB_DIR = /usr/local/lib
OBJS_MAIN = main.o
OBJS_EC_UART_232 = ec_uart_232.o
OBJS_EC_UART_485 = ec_uart_485.o
OBJS_EC_MANAGE_PLCE = ec_manage_plce.o
OBJS_EC_SOCKET_VIDEO = ec_socket_video.o
OBJS_EC_MQTT_ANDROID = ec_mqtt_android.o
OBJS_EC_SQLITE = ec_sqlite.o
OBJS_EC_STORE_INFO = ec_store_info.o
OBJS_EC_MANAGE_CAMERA = ec_manage_camera.o
OBJS_DEAL_REQUEST_LOOP = deal_request_loop.o
OBJS_PUSH_VIDEO = push_video.o
TARGET = ecSmartFire
RM = rm -rf
MV = mv
CP = cp -r
LDCONFIG = ldconfig
OBJS = $(OBJS_MAIN) $(OBJS_EC_UART_232) $(OBJS_EC_UART_485) $(OBJS_EC_MANAGE_PLCE)
$(OBJS_EC_SOCKET_VIDEO) \
$(OBJS_EC_MQTT_ANDROID) $(OBJS_EC_SQLITE) $(OBJS_EC_STORE_INFO) $(OBJS_EC_MANAGE_CAMERA)
$(OBJS_DEAL_REQUEST_LOOP) \
$(OBJS_PUSH_VIDEO)
$(TARGET):$(OBJS)
$(LD) -o $(OUTPUT_DIR)/$(TARGET) $(OBJS) $(CFLAGS_OTHERS_LIB) $(LIB_FOR_SRS) $(LINK_OPTION)
$(STRIP) $(OUTPUT_DIR)/$(TARGET)
$(OBJS_MAIN):
$(CC) -c $(SRC_DIR)/main.c $(COMPILE_ALL_OPTION)
$(OBJS_EC_UART_232):
$(CC) -c $(SRC_DIR)/ec_uart_232.c $(COMPILE_ALL_OPTION)
$(OBJS_EC_UART_485):
$(CC) -c $(SRC_DIR)/ec_uart_485.c $(COMPILE_ALL_OPTION)
$(OBJS_EC_MANAGE_PLCE):
$(CC) -c $(SRC_DIR)/ec_manage_plce.c $(COMPILE_ALL_OPTION)
$(OBJS_EC_SOCKET_VIDEO):
$(CC) -c $(SRC_DIR)/ec_socket_video.c $(COMPILE_ALL_OPTION)
$(OBJS_EC_MQTT_ANDROID):
$(CC) -c $(SRC_DIR)/ec_mqtt_android.c $(COMPILE_ALL_OPTION)
$(OBJS_EC_SQLITE):
$(CC) -c $(SRC_DIR)/ec_sqlite.c $(COMPILE_ALL_OPTION)
$(OBJS_EC_STORE_INFO):
$(CC) -c $(SRC_DIR)/ec_store_info.c $(COMPILE_ALL_OPTION)
$(OBJS_EC_MANAGE_CAMERA):
$(CC) -c $(SRC_DIR)/ec_manage_camera.c $(COMPILE_ALL_OPTION)
$(OBJS_DEAL_REQUEST_LOOP):
$(CC) -c $(SRC_DIR)/deal_request_loop.c $(COMPILE_ALL_OPTION)
$(OBJS_PUSH_VIDEO):
$(CC) -c $(SRC_DIR)/push_video.c $(COMPILE_ALL_OPTION)
.PHONY:clean copylib
clean:
-$(RM) $(OUTPUT_DIR)/* $(OBJS)
copylib:
$(CP) $(LIB_FOR_MQTT) $(SYS_LOCAL_LIB_DIR)/
$(CP) $(LIB_FOR_JSON) $(SYS_LOCAL_LIB_DIR)/
$(CP) $(LIB_FOR_SQLITE3) $(SYS_LOCAL_LIB_DIR)/
$(LDCONFIG)
make error 1:
...
no errors
...
aarch64-linux-gnu-gcc -c ./src/ec_store_info.c -Wall -Wcomment -Wformat -Wmissing-braces -
Wswitch -Wuninitialized -Wbad-function-cast -Waggregate-return -Wmultichar -Wsign-compare -
Wshadow
aarch64-linux-gnu-gcc -c ./src/ec_manage_camera.c -Wall -Wcomment -Wformat -Wmissing-braces -
Wswitch -Wuninitialized -Wbad-function-cast -Waggregate-return -Wmultichar -Wsign-compare -
Wshadow
aarch64-linux-gnu-gcc -c ./src/deal_request_loop.c -Wall -Wcomment -Wformat -Wmissing-braces -
Wswitch -Wuninitialized -Wbad-function-cast -Waggregate-return -Wmultichar -Wsign-compare -
Wshadow
aarch64-linux-gnu-gcc -c ./src/push_video.c -Wall -Wcomment -Wformat -Wmissing-braces -Wswitch
-Wuninitialized -Wbad-function-cast -Waggregate-return -Wmultichar -Wsign-compare -Wshadow
./src/push_video.c: In function 'PushVideoToServer':
./src/push_video.c:21:43: warning: pointer targets in passing argument 2 of
'srs_h264_write_raw_frames' differ in signedness [-Wpointer-sign]
ret = srs_h264_write_raw_frames(Rtmp, data, dataSize, DTS, PTS);
^~~~
In file included from ./src/push_video.c:2:
./src/../head/srs_librtmp/srs_librtmp.h:465:12: note: expected 'char *' but argument is of type
'unsigned char *'
extern int srs_h264_write_raw_frames(srs_rtmp_t rtmp, char* frames, int frames_size, uint32_t
dts, uint32_t pts);
^~~~~~~~~~~~~~~~~~~~~~~~~
./src/push_video.c: In function 'PushVideoFunction':
./src/push_video.c:86:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
aarch64-linux-gnu-ld -o ./output/ecSmartFire main.o ec_uart_232.o ec_uart_485.o ec_manage_plce.o
ec_socket_video.o ec_mqtt_android.o ec_sqlite.o ec_store_info.o ec_manage_camera.o
deal_request_loop.o push_video.o ./lib/srslibrtmp_lib/* -lpaho-mqtt3a -ljson-c -lsqlite3 -lm
-lc -lpthread -ldl -lstdc++ -static
aarch64-linux-gnu-ld: cannot find -lstdc++
make: *** [Makefile:51: ecSmartFire] Error 1
make error 2:
...
/usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-
gnu/bin/ld: cannot find -lpaho-mqtt3a
/usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-
gnu/bin/ld: ./lib/srslibrtmp_lib/srs_librtmp.a(srs_lib_simple_socket.o):
in function `srs_hijack_io_connect(void*, char const*, int)':
solved it.
1,as MadScientist said, I always use gcc to compile not ld.
2,I use option -Wl,-Bstatic and -Wl,-Bdynamic to separte static library and dynamic library.
$(TARGET):$(OBJS)
$(CC) -L $(LIB_FOR_SRS) -o $(OUTPUT_DIR)/$(TARGET) $(OBJS) -Wl,-Bstatic -lssl -
lcrypto \
-Wl,-Bdynamic $(DYNAMIC_LINK_OPTION) $(STATIC_LINK_OPTION)
$(STRIP) $(OUTPUT_DIR)/$(TARGET)
friends, I have a question about linking. I have a problem with linking the project.
I have tree of files:
ffmpeg4.1_custom
fftools
ffmpeg.o
libavfilter
libavfilter.so.
make has only one command to finish - this:
$ make -n
printf "LD\t%s\n" ffmpeg_g; gcc -Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L/usr/local/lib -Wl,--as-needed -Wl,-z,noexecstack -Wl,--warn-common -Wl,-rpath-link=libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil:libavresample -o ffmpeg_g fftools/ffmpeg_opt.o fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o fftools/cmdutils.o fftools/ffmpeg.o -lavdevice -lavfilter -lavformat -lavcodec -lavresample -lpostproc -lswresample -lswscale -lavutil -lm -lxcb -lxcb-shape -lxcb-xfixes -lasound -lSDL2 -lsndio -lXv -lX11 -lXext -pthread -lm -lva -lm -lz -lssl -lcrypto -lvpx -lm -lvpx -lm -lvpx -lm -lvpx -lm -pthread -lm -llzma -lz -lfdk-aac -lopenjp2 -lx264 -lva -lm -lm -lm -lm -pthread -lva-drm -lva -lva-x11 -lva -lm -lva -lXv -lX11 -lXext -ldl
printf "STRIP\t%s\n" ffmpeg; strip -o ffmpeg ffmpeg_g
I check my function in ffmpeg.o:
$ nm fftools/ffmpeg.o | grep my_func
U my_func
I check the same in libavfilter.so:
$ nm libavfilter/libavfilter.so | grep my_func
00000000000b2f8e t my_func
I run full command that links these 2 files:
$ gcc -Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L/usr/local/lib -Wl,--as-needed -Wl,-z,noexecstack -Wl,--warn-common -Wl,-rpath-link=libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil:libavresample -o ffmpeg_g fftools/ffmpeg_opt.o fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o fftools/cmdutils.o fftools/ffmpeg.o -lavdevice -lavfilter -lavformat -lavcodec -lavresample -lpostproc -lswresample -lswscale -lavutil -lm -lxcb -lxcb-shape -lxcb-xfixes -lasound -lSDL2 -lsndio -lXv -lX11 -lXext -pthread -lm -lva -lm -lz -lssl -lcrypto -lvpx -lm -lvpx -lm -lvpx -lm -lvpx -lm -pthread -lm -llzma -lz -lfdk-aac -lopenjp2 -lx264 -lva -lm -lm -lm -lm -pthread -lva-drm -lva -lva-x11 -lva -lm -lva -lXv -lX11 -lXext -ldl
fftools/ffmpeg.o: In function `configure_filtergraph':
ffmpeg.c:(.text+0x6892): undefined reference to `my_func'
collect2: error: ld returned 1 exit status
If it plays any role, my function's prototype is in avfilter.h, code is in avfilter.c and it is used in ffmpeg.c
What am I doing wrong?
Linux Mint 19
gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
The 'nm' output indicate my_func is "local" to libavfilter.so - it is marked with 't'. You can only refer to "global" functions - those will be marked with 'T'
From nm man page:
The symbol type. At least the following types are used; others are, as well, depending on the object file
format. If lowercase, the symbol is usually local; if uppercase, the symbol is global (external). There
are however a few lowercase symbols that are shown for special global symbols ("u", "v" and "w").
Access to local symbols is limited to the same module.
I am trying to compile a program and I have to set the paths to the NETCDF inc and lib directories in the Makefile as well as set the gfortran and c compiler settings. The variables were already named as shown below, it just told me to edit the paths/options which I have tried to do. Here is what I have for my netcdf inc and lib, as well as the hdf5:
NETCDFINC = -I$(NETCDFF_INCDIR) -I$(NETCDFC_INCDIR)
NETCDFLIB = -Wl,-rpath=$(NETCDFF_LIBDIR) -L$(NETCDFF_LIBDIR) -Wl,-
rpath=$(NETCDFC_LIBDIR) -L$(NETCDFC_LIBDIR) -Wl,-rpath=$(HDF5_LIBDIR) -
L$(HDF5_LIBDIR) -lhdf5_hl -lhdf5 -lz
Note that the NETCDFLIB is on one line on my file, and the paths of the variables are correct, but the syntax may not be.
Next for the fortran and c compiler information I have the following:
FC = gfortran -m64 -g -O0 -ffixed-line-length-132 -Wunused -Wuninitialized
CC = gcc
CFLAGS = -m64 -c -g -I. -DLONG32 -DUNDERSCORE -DLITTLE -Wunused -
Wuninitialized
Finally, when I run the program I first get a bunch of warnings such as:
oban_namelist.f90:495.29:
real :: flt
1
Warning: Unused variable 'flt' declared at (1)
Followed by a bunch of undefined reference errors such as:
oban.o: In function `check':
/uufs/chpc.utah.edu/common/home/zpu-
group3/dhodges/DART/data/radar/opaws/oban.f90:1902: undefined reference to
`__netcdf_MOD_nf90_strerror'
The error shouldn't be in this oban.o function since I didn't write it. The only things I have edited in the program I listed above for the netcdf path and gfortran/c information and so I think the error lies there. This is my first question on here, so if I missed anything you need feel free to ask. What can I try?
Edit: By request, this is the entire makefile I am using. Also, I just type 'make' to compile it per the instructions in the README file.
# Makefile for creating the OPAWS analysis software
#
# Rev: 02/05/10 LJW
# 12/05/10 DCD
# 02/11/11 LJW
#
# netCDF4 libs - you need to fill in the blanks
NETCDFINC = -I$(NETCDFF_INCDIR) -I$(NETCDFC_INCDIR)
NETCDFLIB = -Wl,-rpath=$(NETCDFF_LIBDIR) -L$(NETCDFF_LIBDIR) -Wl,-rpath=$(NETCDFC_LIBDIR) -L$(NETCDFC_LIBDIR) -Wl,-rpath=$(HDF5_LIBDIR) -
L$(HDF5_LIBDIR) -lhdf5_hl -lhdf5 -lz
# Fortran and C compiler information - various configurations are setup, try and find one close
#=====>> Gfortran
#
FC = gfortran -m64 -g -O0 -ffixed-line-length-132 -Wunused -Wuninitialized
CC = gcc
CFLAGS = -m64 -c -g -I. -DLONG32 -DUNDERSCORE -DLITTLE -Wunused -Wuninitialized
# Leave this stuff alone
EXEC = x.oban
EXECcs = x.clutter_stats
EXECmd = mosaic_2_dart
OBJS = DART.o oban_module.o dict_module.o oban_namelist.o derived_types.o util.o fileio.o read_dorade.o binio.o v5d.o
OBJScs = DART.o dict_module.o oban_namelist.o derived_types.o fileio.o util.o read_dorade.o binio.o v5d.o
OBJSmd = DART.o dict_module.o oban_namelist.o derived_types.o fileio.o util.o read_dorade.o binio.o v5d.o
default: $(EXEC) $(EXECcs) $(EXECmd)
$(EXEC): $(OBJS) oban.o
$(FC) $(OPT) -o $(EXEC) oban.o $(OBJS) $(NETCDFLIB)
$(EXECcs): $(OBJScs) clutter_stats.o
$(FC) $(OPT) -o $(EXECcs) clutter_stats.o $(OBJScs) $(NETCDFLIB)
$(EXECmd): $(OBJSmd) mosaic_2_dart.o
$(FC) $(OPT) -o $(EXECmd) mosaic_2_dart.o $(OBJSmd) $(NETCDFLIB)
clean:
rm $(EXEC) oban.o $(OBJS) $(EXECcs) clutter_stats.o $(OBJScs) $(EXECmd) mosaic_2_dart.o $(OBJSmd) *.mod ncgen.input *.pyc sweep_file_list.txt
# Individual compilation instructions
oban.o: oban.f90 structures.inc opaws.inc DART.o
$(FC) $(OPT) -c $(NETCDFINC) oban.f90
clutter_stats.o: clutter_stats.f90 opaws.inc
$(FC) $(OPT) -c $(NETCDFINC) clutter_stats.f90
mosaic_2_dart.o: mosaic_2_dart.f90 opaws.inc
$(FC) $(OPT) -c $(NETCDFINC) mosaic_2_dart.f90
oban_module.o: oban_module.f90 derived_types.o opaws.inc
$(FC) $(OPT) -c oban_module.f90
read_dorade.o: read_dorade.c read_dorade.h
$(CC) $(CFLAGS) -c read_dorade.c
fileio.o: fileio.f90
$(FC) $(OPT) $(NETCDFINC) -c fileio.f90
util.o: util.f opaws.inc structures.inc
$(FC) $(OPT) -c util.f
DART.o: DART.f
$(FC) $(OPT) -c DART.f
derived_types.o: derived_types.f90
$(FC) $(OPT) -c derived_types.f90
oban_namelist.o: oban_namelist.f90 opaws.inc
$(FC) $(OPT) -c oban_namelist.f90
dict_module.o: dict_module.f90
$(FC) $(OPT) -c dict_module.f90
binio.o: binio.c
$(CC) $(CFLAGS) binio.c -o binio.o
v5d.o: v5d.c
$(CC) $(CFLAGS) v5d.c -o v5d.o
The problem was solved by editing the NETCDFLIB line as follows:
I edited the NETCDFLIB line as follows and it works: NETCDFLIB = -Wl,-
rpath=$(NETCDFF_LIBDIR) -L$(NETCDFF_LIBDIR) -Wl,-rpath=$(NETCDFC_LIBDIR) -
L$(NETCDFC_LIBDIR) -lnetcdff -lnetcdf -lm -Wl,-rpath=$(HDF5_LIBDIR) -
L$(HDF5_LIBDIR) -lhdf5_hl -lhdf5 -lz
Basically I just needed to add:
-lnetcdff -lnetcdf -lm
This allowed for the compiler to get access to the libraries it needed that were originally undefined.
Based on the Limifrog STM32L board examples, I am trying to setup my own toolchain for ARM development (STM32F40x based).
I get an error:
C:\Users\pmu\embedded\empty_stm32>make
arm-none-eabi-gcc -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -I
./inc -I./../Libraries/CMSIS/Device/ST/STM32F4xx/Include -I./../Libraries/CMSIS/
Include -Os -Wall -ffunction-sections -fdata-sections -fno-exceptions -Wno-write
-strings -o main src/main.c
c:/program files (x86)/gnu tools arm embedded/4.9 2015q3/bin/../lib/gcc/arm-none
-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m/fpu\libc.a(lib_a-exit.o): In
function `exit':
exit.c:(.text.exit+0x16): undefined reference to `_exit'
collect2.exe: error: ld returned 1 exit status
make: *** [main] Error 1
when compiling:
#include "My_Globals.h"
int main(void) {
while(1) {
}
return 0;
}
What does this error mean? Why does it not occur in the Board examples above?
The Makefile
# Compilation Tools
CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld
CP = arm-none-eabi-objcopy
OD = arm-none-eabi-objdump
SIZE = arm-none-eabi-size
# Optimization (ß,1,2,s)
OPT = s
ROOT = ./..
CMSIS_DIR = $(ROOT)/Libraries/CMSIS
HAL_DIR = $(ROOT)/Libraries/CMSIS/Include
SRC = ./src
INC_LOCAL = ./inc
INCLUDES = \
$(INC_LOCAL) \
$(CMSIS_DIR)/Device/ST/STM32F4xx/Include \
$(CMSIS_DIR)/Include
ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
LD_FLAGS =
# Compiler flags
CFLAGS = \
$(ARCH_FLAGS) \
$(addprefix -I,$(INCLUDES)) \
-O$(OPT) \
-Wall \
-ffunction-sections \
-fdata-sections \
-fno-exceptions \
-Wno-write-strings
main:
#echo "start"
#echo $#
$(CC) $(LDFLAGS) $(CFLAGS) -o $# src/main.c
Now, what libraries can be used to re-use the implementation of _exit() from elsewhere?
First of all : I am a newbee in linux.
2nd -- I have seen What is missing in my makefile?
but did not still get what is wrong with my make file. Though I am getting the same errors he was getting.
Error that I am getting after running the makefile:
user#ubuntu:~/Documents/Myfiles/Adaptive Doppler$ make adaptiveav
gcc -o adaptiveav simpsimaav.o findvel.o do_fft.o four1.o subdc.o do_peak_n.o -g
simpsimaav.o: In function `main':
/home/user/Documents/Myfiles/Adaptive Doppler/simpsimaav.c:179: undefined reference to `cos'
/home/user/Documents/Myfiles/Adaptive Doppler/simpsimaav.c:180: undefined reference to `sin'
/home/user/Documents/Myfiles/Adaptive Doppler/simpsimaav.c:299: undefined reference to `sin'
/home/user/Documents/Myfiles/Adaptive Doppler/simpsimaav.c:299: undefined reference to `sin'
/home/user/Documents/Myfiles/Adaptive Doppler/simpsimaav.c:299: undefined reference to `sin'
/home/user/Documents/Myfiles/Adaptive Doppler/simpsimaav.c:325: undefined reference to `sqrt'
/home/user/Documents/Myfiles/Adaptive Doppler/simpsimaav.c:325: undefined reference to `sqrt'
/home/user/Documents/Myfiles/Adaptive Doppler/simpsimaav.c:326: undefined reference to `cos'
/home/user/Documents/Myfiles/Adaptive Doppler/simpsimaav.c:327: undefined reference to `sin'
simpsimaav.o: In function `rayleigh':
/home/user/Documents/Myfiles/Adaptive Doppler/simpsimaav.c:418: undefined reference to `log'
/home/user/Documents/Myfiles/Adaptive Doppler/simpsimaav.c:418: undefined reference to `sqrt'
/home/user/Documents/Myfiles/Adaptive Doppler/simpsimaav.c:421: undefined reference to `sqrt'
four1.o: In function `four1':
/home/user/Documents/Myfiles/Adaptive Doppler/four1.c:47: undefined reference to `sin'
/home/user/Documents/Myfiles/Adaptive Doppler/four1.c:49: undefined reference to `sin'
collect2: error: ld returned 1 exit status
make: *** [adaptiveav] Error 1
-------------------------------------------------------------
My make file :
OBJS= main.o do_fft.o find_m.o read_sig.o write_out.o allocin.o\
getopts.o read_form.o read_bin.o optlist.o usage.o normalize.o \
enquire.o init_fft.o subdc.o skip.o shortfile.o open_out.o \
han_win.o getyn.o record.o do_mom.o frq_arry.o four1.o look_nfo.o\
do_peak.o coefs_out.o do_smooth.o do_maxf.o accum.o pspect.o except.o\
get_info.o open_in.o test_read.o getstr.o getint.o open_nfo.o line_flush.o \
simpsim1.o
# Note: these routines are found in Lib/lib.ar
LIBOBJS= debug.c div_by.c getint.c getstr.c \
init_ap.c look_nfo.c open_in.c open_nfo.c test_read.c
# LIBS= -lm /usr/local/src/Cspect/Lib/lib.ar -lfpe
LIBS = -lm
CFLAGS= -g
rtest: rtest.o realft.o four1.o
gcc -o rtest rtest.o realft.o four1.o -lm $(CFLAGS)
itest: itest.o realft.o four1.o
gcc -o itest itest.o realft.o four1.o -lm $(CFLAGS)
test: test.o four1.o
gcc -o test test.o four1.o -lm $(CFLAGS)
invtest: invtest.o four1.o
gcc -o invtest invtest.o four1.o -lm $(CFLAGS)
tabtest: test.o ffttab.o
gcc -o test test.o ffttab.o -lm $(CFLAGS)
cspect: ${OBJS}
gcc -o cspect.exe ${OBJS} ${LIBS} ${CFLAGS}
rdtest: rdtest.o read_form.o
gcc -o rdtest rdtest.o read_form.o -g
fttest: sine.o do_fft.o four1.o subdc.o do_peak.o
gcc -o fttest sine.o do_fft.o four1.o subdc.o do_peak.o
adaptive: simpsima.o findvel.o do_fft.o four1.o subdc.o do_peak.o
gcc -o adaptive simpsima.o findvel.o do_fft.o four1.o subdc.o do_peak.o -g
notadaptive: simpsimna.o findvel.o do_fft.o four1.o subdc.o do_peak.o
gcc -o notadaptive simpsimna.o findvel.o do_fft.o four1.o subdc.o do_peak.o -g
adaptivevold: simpsimavold.o findvel.o do_fft.o four1.o subdc.o do_peak.o
gcc -o adaptivevold simpsimavold.o findvel.o do_fft.o four1.o subdc.o do_peak.o
adaptivev: simpsimav.o findvel.o do_fft.o four1.o subdc.o do_peak_n.o
gcc -o adaptivev simpsimav.o findvel.o do_fft.o four1.o subdc.o do_peak_n.o -g
notadaptivev: simpsimnav.o findvel.o do_fft.o four1.o subdc.o do_peak_n.o
gcc -o notadaptivev simpsimnav.o findvel.o do_fft.o four1.o subdc.o do_peak_n.o -g
adaptiveav: simpsimaav.o findvel.o do_fft.o four1.o subdc.o do_peak_n.o
gcc -o adaptiveav simpsimaav.o findvel.o do_fft.o four1.o subdc.o do_peak_n.o -g
.c.o:
gcc -c ${CFLAGS} $*.c
#simpsim.o: simpsim.c
# gcc -c simpsim1.c
: spect
strip spect
chmod 755 spect
chgrp user spect
mv spect /usr/local/bin
This is not the directory where my lib.ar is : Is it probably for this?
# LIBS= -lm /usr/local/src/Cspect/Lib/lib.ar -lfpe
LIBS = -lm"
and I dont want you to do my works... just suggest me anything... or any useful website where they talk about these things...
I hope not to get rude comments just because I am new.
Thanks.
The undefined references are all math functions found in libm.a. The part with the -lm in the Makefile did not make it to the gcc command. Try adding -lm to the gcc command and it should work. Specifically, this
adaptiveav: simpsimaav.o findvel.o do_fft.o four1.o subdc.o do_peak_n.o
gcc -o adaptiveav simpsimaav.o findvel.o do_fft.o four1.o subdc.o do_peak_n.o -g
is missing a reference to $(LIBS) at the end.
adaptiveav: simpsimaav.o findvel.o do_fft.o four1.o subdc.o do_peak_n.o
gcc -o adaptiveav simpsimaav.o findvel.o do_fft.o four1.o subdc.o do_peak_n.o -g
As you can see the -lm switch isn't on that line. So the references to cos are unresolved.