1

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     =
Community
  • 1
  • 1
Momergil
  • 2,213
  • 5
  • 29
  • 59

1 Answers1

1

I've never seen a Linux library end in .lib. That is a Microsoft thing. Are you sure calculos.lib is a valid Linux lib?

You can also check using the ar command to see if the objects you expect are in the libs. For example:

ar t mylib.a

It sounds to me like the libs you are trying to use were either not built for Linux in the case of calculos or don't have the symbols exported properly to be used in your application. These are just a few guesses; I don't have enough information to go on. :)

Momergil
  • 2,213
  • 5
  • 29
  • 59
ambershark
  • 111
  • 1
  • 1
  • 4
  • Thanks for the reply. I modified the the `calculos` to be a `.a` file now. The interesting thing is that it was being successfully used as a Linux library in another project even in the `.lib` format. After the change, I did some tests and the problem persists: "cannot find -lcalculos". I suppose there is something lacking which would tell qmake that this is a library (as you suggested). I'm appending to my question another Makefile of a library that qmake correctly recognizes so everyone may notice easily if something is lacking. – Momergil Sep 09 '14 at 16:45
  • 1
    Well that makes sense though. When you do -lxxx gcc will look for libxxx.a or libxxx.so. So it makes sense that calculos.lib is not found by the -l syntax. In that case you have to link it using the filename but without the -l. Like LIBS += calculous.lib or /path/to/calculos.lib. Either of those should work. The first one only if you have the path defined with -L/path/to/lib. – ambershark Sep 09 '14 at 22:16
  • 1
    Also, in the past when it looks like I've linked "correctly" to a lib and then my app complains about missing externals like yours is doing, it usually turns out that the lib was not compatible (i.e. didn't find proper exported functions). Usually this happens to me when doing windows code using mingw and trying to use MSVC .libs instead of mingw generated .as. – ambershark Sep 09 '14 at 22:20
  • it's working! :D Thanks for the help! Although the final solution didn't show as expected: as I sad, there are 2 libs I need to use, the one is `c6run` and the other is `calculos` and I was having problems when including both libs directly into my project. Fortunately the now `libcalculos.a` itself includes `c6run`, so when I managed to successfully include it into my project, it immediately made `c6run` available to it as well dismissing the need for a direct inclusion. BTOH your proposed solution for `c6run` is probably correct: no one knows how it was compiled \o/ – Momergil Sep 10 '14 at 12:46
  • would you mind editing your question to include this extra points discussed in the comments section? As for now, it doesn't work as a valid answer, but with such editions I can mark it as such! And thanks for the help once again! – Momergil Sep 10 '14 at 12:48