简体   繁体   中英

Statically link against pocketsphinx (Library)

I am developing a little program with pocketsphinx (speech to text - library). On Windows i was using Code::Blocks as development environment and i had success to build a program. Now i try to port my program to Linux and i am having little problems to link against pocketsphinx.

This is the Makefile:

CC = g++
CFLAGS = -Wall -std=c++11
LDFLAGS = -I/usr/local/include/sphinxbase -I/usr/local/include/pocketsphinx

OBJ = obj/Application.o obj/Main.o obj/Recorder.o

all: $(OBJ)
    $(CC) -L/usr/local/lib -o bin/Eve $(OBJ) -s -lsphinxbase -lpocketsphinx

obj/Main.o: src/Main.cpp
    $(CC) $(CFLAGS) $(LDFLAGS) -c src/Main.cpp -o obj/Main.o

obj/Application.o: src/Application.cpp src/Application.hpp
    $(CC) $(CFLAGS) $(LDFLAGS) -c src/Application.cpp -o obj/Application.o

obj/Recorder.o: src/Recorder.cpp src/Recorder.hpp
    $(CC) $(CFLAGS) $(LDFLAGS) -c src/Recorder.cpp -o obj/Recorder.o

It is the same which i was using on Windows, i just adjusted the file path.

I am receiving the following error:

$ make
g++ -Wall -std=c++11 -I/usr/local/include/sphinxbase -I/usr/local/include/pocketsphinx -c src/Application.cpp -o obj/Application.o
g++ -Wall -std=c++11 -I/usr/local/include/sphinxbase -I/usr/local/include/pocketsphinx -c src/Main.cpp -o obj/Main.o
g++ -Wall -std=c++11 -I/usr/local/include/sphinxbase -I/usr/local/include/pocketsphinx -c src/Recorder.cpp -o obj/Recorder.o
g++ -L/usr/local/lib -o bin/Eve obj/Application.o obj/Main.o obj/Recorder.o -s  -lsphinxbase -lpocketsphinx
obj/Recorder.o: In function `Recorder::Recorder()':
Recorder.cpp:(.text+0x1c0): undefined reference to `ad_open_sps'
Recorder.cpp:(.text+0x20d): undefined reference to `ad_read'
Recorder.cpp:(.text+0x215): undefined reference to `cont_ad_init'
obj/Recorder.o: In function `Recorder::~Recorder()':
Recorder.cpp:(.text+0x2f3): undefined reference to `cont_ad_close'
Recorder.cpp:(.text+0x303): undefined reference to `ad_close'
obj/Recorder.o: In function `Recorder::recognizeFromMicrophone()':
Recorder.cpp:(.text+0x37a): undefined reference to `ad_start_rec'
Recorder.cpp:(.text+0x395): undefined reference to `cont_ad_calib'
Recorder.cpp:(.text+0x3f0): undefined reference to `cont_ad_read'
Recorder.cpp:(.text+0x4e6): undefined reference to `cont_ad_read'
Recorder.cpp:(.text+0x5b5): undefined reference to `ad_stop_rec'
Recorder.cpp:(.text+0x5d8): undefined reference to `ad_read'
Recorder.cpp:(.text+0x5f4): undefined reference to `cont_ad_reset'
collect2: error: ld returned 1 exit status
make: *** [all] Fehler 1

I don't think that it is a name mangling problem, since i built the lib on my own using the provided Makefile.

What can i do to link against the lib without errors?

EDIT: I figured out how to make it work. I simply modified the rule of the target "all" to this:

$(CC) -static -L/usr/local/lib -o bin/Eve $(OBJ) -s  -lpocketsphinx -lsphinxbase -lsphinxad -lpthread

Functions like ad_read are defined in libsphinxad library, you need to add it to your linker command line:

g++ -static -L/usr/local/lib -o bin/Eve obj/Application.o obj/Main.o obj/Recorder.o \
-lpocketsphinx -lsphinxbase -libsphinxad

Please note that the order of libraries is important.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM