I'm having a problem when including two libraries (not made by me) into my (pure C) project in Qt Creator (using qmake + GCC on Linux Ubuntu).
I know that, to include a lib, one uses the LIBS
directive as explained in this SO answer; and I have successfully inserted libraries both in Linux as well as in Windows this way. Even more, in this same problematic project I have two successfully inserted libraries.
But now I'm having a problem including this two other libs in this same project. One of this libraries is C6RUN, required for conversation between two processors, and inside the library's folder there is a /bin
and a /lib
folder; the first has some files with no extension (they are not a .a or .lib) while the second have, inside two child folders, a set of .a . The other library is inside a folder with a /lib
subfolder with a .lib inside. Both of them are working 100% in a project in Eclipse (so no qmake/Qt Creator involved). I mentioned the /bin
folder of the first library because in a Makefile related to the Eclipse-based project two of its files are referenced despite not being formally library files.
When trying to link both libraries in the .pro, I do EXACTLY the same thing as always: add the path with -L
plus the name of the lib with -l
. When I try to do that with those two libs, errors occur. What follows is the list with actions + results (actually I tried even some other options, but none of the results were different from the two shown below):
First lib 1
.pro
LIBS += -L$${COMMON_PATH}/linux-devkit/c6run/lib/c6run_dsp -llibc6run
result
error: connot find -llibc6run
First lib 2
.pro
LIBS += -L$${COMMON_PATH}/linux-devkit/c6run/lib/c6run_dsp -lc6run
result
compiles fine.
when calling a respective method inside main.cpp / int main():
error: undefined reference of <method name>
First lib 3
.pro
LIBS += -L$${COMMON_PATH}/linux-devkit/c6run/bin -lc6runlib-ar
result
error: connot find -lc6runlib-ar
Second lib 1
.pro
LIBS += -L$${RE8K_REPO}/main_projects/lib_calc_dsp/lib -lcalculos
result
error: connot find -lcalculos
Second lib 2
.pro
LIBS += -L$${RE8K_REPO}/main_projects/lib_calc_dsp/lib/calculos.lib
result
compiles fine.
when calling a respective method inside main.cpp / int main():
error: undefined reference of <method name>
So, what could I be missing?
Here is another Makefile that is used to compile a library that is successfully used in the same project:
Calculos Makefile
# ----------------------------------------------------------------------------
# Name of the ARM GCC cross compiler & archiver
# ----------------------------------------------------------------------------
ARM_TOOLCHAIN_PREFIX = arm-arago-linux-gnueabi-
ARM_TOOLCHAIN_PATH = /re8k/linux-devkit
ARM_CC := $(ARM_TOOLCHAIN_PATH)/bin/$(ARM_TOOLCHAIN_PREFIX)gcc
ARM_AR := $(ARM_TOOLCHAIN_PATH)/bin/$(ARM_TOOLCHAIN_PREFIX)ar
# Get any compiler flags from the environment
ARM_CFLAGS = $(CFLAGS)
ARM_CFLAGS += -std=gnu99 \
-Wdeclaration-after-statement -Wall -Wno-trigraphs \
-fno-strict-aliasing -fno-common -fno-omit-frame-pointer \
-c -O3
ARM_LDFLAGS = $(LDFLAGS)
ARM_LDFLAGS+=-lm -lpthread
ARM_ARFLAGS = rcs
# ----------------------------------------------------------------------------
# Name of the DSP C6RUN compiler & archiver
# TI C6RunLib Frontend (if path variable provided, use it, otherwise assume
# the tools are in the path)
# ----------------------------------------------------------------------------
C6RUN_TOOLCHAIN_PREFIX = c6runlib-
C6RUN_TOOLCHAIN_PATH = $(ARM_TOOLCHAIN_PATH)/c6run
C6RUN_CC := $(C6RUN_TOOLCHAIN_PATH)/bin/$(C6RUN_TOOLCHAIN_PREFIX)cc
C6RUN_AR := $(C6RUN_TOOLCHAIN_PATH)/bin/$(C6RUN_TOOLCHAIN_PREFIX)ar
C6RUN_CFLAGS = -c -mt -O3
C6RUN_ARFLAGS = rcs
# ----------------------------------------------------------------------------
# List of lib source files
# ----------------------------------------------------------------------------
LIB_SRCS := calculos.c
LIB_DSP_OBJS := $(LIB_SRCS:%.c=dsp_obj/%.o)
LIB_OBJS := $(LIB_DSP_OBJS:%.o=%.lib)
all: dsp_obj/.created
$(C6RUN_CC) $(C6RUN_CFLAGS) -o $(LIB_DSP_OBJS) $(LIB_SRCS) -DUSE_DSP;
$(C6RUN_AR) $(C6RUN_ARFLAGS) $(LIB_OBJS) $(LIB_DSP_OBJS);
all_host: dsp_obj/.created
gcc -c -o $(LIB_DSP_OBJS) $(LIB_SRCS);
ar rcs $(LIB_OBJS) $(LIB_DSP_OBJS);
dsp_obj/.created:
@mkdir -p dsp_obj
@touch dsp_obj/.created
clean:
rm -rf dsp_obj;
distclean: clean
Other Makefile
include Makerules.mk
export PATH := $(TGT_GCC_PATH):$(PATH)
printversions:
@echo FWVersion: ${FIRWMARE_VERSION}
@echo BuildTag: ${BUILDTAG}
@echo
dev_lib:
make -f ../build/MakeDevLib.mk -I./ all
tgt_lib:
make -f ../build/MakeTgtLib.mk -I./ all
all: printversions tgt_lib dev_lib
install: tgt_lib dev_lib
@mkdir -p ../../common/lib
cp lib/libhal* ../../common/lib
@mkdir -p ../../common/include
@rm ../../common/include/hal -rf
cp src/hal ../../common/include/ -r
clean:
make -f ../build/MakeDevLib.mk -I./ clean
make -f ../build/MakeTgtLib.mk -I./ clean
@rm lib -rf
Makerules.mk
BUILDTAG = $(shell svn info -r 'HEAD' | grep Revision: | egrep -o "[0-9]+") #Or: BUILDTAG = $(shell svn info -r 'HEAD' ) or: BUILDTAG = $(shell svnversion)
FIRWMARE_VERSION = $(shell cat lib_version.txt)-$(shell date --iso)
TGT_LINUX_INCLUDE_DIR = $(shell cat ../../host_cfg/linux-tgt-include-dir.txt)
### TOOL CHAIN ###
CC=cc
AR=ar
STRIP=strip
TGT_GCC_PATH = $(shell cat ../../host_cfg/gcc-tgt-path.txt)
TGT_CC= arm-arago-linux-gnueabi-gcc
TGT_AR= arm-arago-linux-gnueabi-ar
TGT_STRIP= arm-arago-linux-gnueabi-strip
TGT_LD= arm-arago-linux-gnueabi-ld
### SOURCES ###
SOURCE_FOLDER = src
SRC_DIRS = \
src/comm \
src
TEST_SRC_DIRS = \
test/mocks \
test/comm \
test
### PROJECT ###
TARGET = hal
### TEST FRAMEWORK ###
CPPUTEST_HOME = ../../common/CppUTest
### C FLAGS ###
ALL_CCPPFLAGS = -Isrc -I ../../common/include -D AUTO_GEN_BUILD_TAG='"${BUILDTAG}"' -D AUTO_GEN_FIRWMARE_VERSION='"${FIRWMARE_VERSION}"' -g -fPIC -I../../kernel/packages/linux/include
ALL_CONLYFLAGS = -std=gnu99
ALL_CPPONLYFLAGS =
TEST_CFLAGS = -I$(CPPUTEST_HOME)/include/ -D SYSTEM_UNIT_TEST -D DEBUG
DEV_CCPPFLAGS = -D DEV
TGT_CCPPFLAGS = -D TGT -I $(TGT_LINUX_INCLUDE_DIR)
### LINKER LIBS AND FLAGS ###
DEV_STATIC_LIBS =
TGT_STATIC_LIBS =
#DEV_TEST_STATIC_LIBS = ../../common/lib/libchelper-dev-test.a
#TGT_TEST_STATIC_LIBS = ../../common/lib/libchelper-tgt-test.a
DEV_SHARED_LIBS_PATH =
DEV_SHARED_LIBS = -lzmq -lm -lpthread
TGT_SHARED_LIBS_PATH = -L ../../../../sdcard_files/defaultFiles/lib
TGT_SHARED_LIBS = -lzmq -lm -lpthread
DEV_LDFLAGS =
TGT_LDFLAGS =