I'm trying to set-up a function, using the ffmpeg c api, to re-sample a stream (AVStream format) to fixed (1channel - u8 sample) format.
I'm using ffmpeg libswresample library, but when I try to compile, I get a linker error that is strictly connected to swresample functions.
Let me post the code:
double *resample8(AVFrame *frame, int size, AVCodec* codec){
/* initialization of the output array */
double *out = new double[size];
/* create resampling context */
struct SwrContext *resampleContext;
resampleContext = swr_alloc();
if (!resampleContext) {
fprintf(stderr, "Could not allocate resampler context\n");
return NULL;
}
/* set options */
av_opt_set_int(resampleContext, "in_channel_layout", *(codec->channel_layouts), 0);
av_opt_set_sample_fmt(resampleContext, "in_sample_fmt", *(codec->sample_fmts), 0);
av_opt_set_int(resampleContext, "out_channel_layout", AV_CH_LAYOUT_MONO, 0);
av_opt_set_sample_fmt(resampleContext, "out_sample_fmt", AV_SAMPLE_FMT_U8, 0);
/* initialize the resampling context */
if (swr_init(resampleContext) < 0) {
fprintf(stderr, "Failed to initialize the resampling context\n");
return NULL;
}
return NULL;
}
Here is the inclusion:
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libavutil/opt.h>
#include <libavutil/channel_layout.h>
#include <libavutil/samplefmt.h>
#include <libswresample/swresample.h>
#ifdef __cplusplus
} // end extern "C".
#endif // __cplusplus
And here is the error I get, compiling with netbeans, g++
(additional g++ commands: -lavcodec -lavformat -lavutil -lswresample -lfftw3 -lm)
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: ingresso nella directory "/home/davide/Documenti/Tesi/audiosync-fin/audiosync"
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/audiosync
make[2]: ingresso nella directory "/home/davide/Documenti/Tesi/audiosync-fin/audiosync"
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/main.o.d"
g++ -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/main.o.d" -o build/Debug/GNU-Linux-x86/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/audiosync build/Debug/GNU-Linux-x86/dataReader.o build/Debug/GNU-Linux-x86/main.o build/Debug/GNU-Linux-x86/tansforms.o build/Debug/GNU-Linux-x86/tognuplot.o -lavcodec -lavformat -lavutil -lswresample -lfftw3 -lm
build/Debug/GNU-Linux-x86/dataReader.o: nella funzione "resample8(AVFrame*, int, AVCodec*)":
/home/davide/Documenti/Tesi/audiosync-fin/audiosync/dataReader.cpp:285: riferimento non definito a "av_opt_set_sample_fmt"
/home/davide/Documenti/Tesi/audiosync-fin/audiosync/dataReader.cpp:288: riferimento non definito a "av_opt_set_sample_fmt"
/usr/local/lib/libswresample.so: riferimento non definito a "av_calloc#LIBAVUTIL_54"
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:65: set di istruzioni per l'obiettivo "dist/Debug/GNU-Linux-x86/audiosync" non riuscito
make[2]: *** [dist/Debug/GNU-Linux-x86/audiosync] Errore 1
make[2]: uscita dalla directory "/home/davide/Documenti/Tesi/audiosync-fin/audiosync"
nbproject/Makefile-Debug.mk:62: set di istruzioni per l'obiettivo ".build-conf" non riuscito
make[1]: *** [.build-conf] Errore 2
make[1]: uscita dalla directory "/home/davide/Documenti/Tesi/audiosync-fin/audiosync"
nbproject/Makefile-impl.mk:39: set di istruzioni per l'obiettivo ".build-impl" non riuscito
make: *** [.build-impl] Errore 2
BUILD FAILED (exit value 2, total time: 5s)
here is the linker configuration linker config
I searched for any clue about the linker error, and I found that it could be caused by multiple versions of ffmpeg installed. I removed ubuntu (I'm using 15.04) base installation of ffmpeg and installed ffmpeg 2.7.2 from the tar downloaded by ffmpeg.org
I can't seem to find a solution at the moment, can anyone help?
I think the linking order matters
refer this question
Why does the order in which libraries are linked sometimes cause errors in GCC?
Try this order
libavdevice libavformat libavfilter libavcodec libwscale libavutil libswresample libswscale libpostproc libavresample
Related
I was learning how to multithread in c++ and I run into this problem. I've searched the internet and didn't found a satisfactory answer.
I'm pretty sure the library's directory is included.
This are my system specifications:
Oracle Virtual box 5.2.12
Debian 9
Netbeans 8.2
gcc and g++ 6.3.0
This are the errors
Cannot find include file "/usr/include/c++/6".
unable to resolve identifier future.
unable to resolve identifier get.
This is my tutorials code:
// async example
#include <iostream> // std::cout
#include <future> // std::async, std::future
// a non-optimized way of checking for prime numbers:
bool is_prime (int x) {
std::cout << "Calculating. Please, wait...\n";
for (int i=2; i<x; ++i) if (x%i==0) return false;
return true;
}
int main ()
{
// call is_prime(313222313) asynchronously:
std::future<bool> fut = std::async (is_prime,313222313);
std::cout << "Checking whether 313222313 is prime.\n";
// ...
bool ret = fut.get(); // waits for is_prime to return
if (ret) std::cout << "It is prime!\n";
else std::cout << "It is not prime.\n";
return 0;
}
And this is the building output:
cd '/home/sulheru/NetBeansProjects/20180907/asyncTutorial'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: se entra en el directorio '/home/sulheru/NetBeansProjects/20180907/asyncTutorial'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/asynctutorial
make[2]: se entra en el directorio '/home/sulheru/NetBeansProjects/20180907/asyncTutorial'
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/main.o.d"
g++ -c -g -include /usr/include/c++/6.3.0 -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp
cc1plus: fatal error: /usr/include/c++/6.3.0: No existe el fichero o el directorio
compilation terminated.
nbproject/Makefile-Debug.mk:66: fallo en las instrucciones para el objetivo 'build/Debug/GNU-Linux/main.o'
make[2]: *** [build/Debug/GNU-Linux/main.o] Error 1
make[2]: se sale del directorio '/home/sulheru/NetBeansProjects/20180907/asyncTutorial'
nbproject/Makefile-Debug.mk:59: fallo en las instrucciones para el objetivo '.build-conf'
make[1]: *** [.build-conf] Error 2
make[1]: se sale del directorio '/home/sulheru/NetBeansProjects/20180907/asyncTutorial'
nbproject/Makefile-impl.mk:39: fallo en las instrucciones para el objetivo '.build-impl'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 323ms)
You need the -pthread option in your compiler flags.
Example:
➜ g++ -std=c++11 -pthread async.cpp
➜ ./a.out
Checking whether 313222313 is prime.
Calculating. Please, wait...
It is prime!
I'm experiencing difficulties working with boost::python and boost::python::numpy, with python 2.7, boost 1.67.0, and Eigen3.3. My compiler is g++ (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0.
I'm trying to convert Eigen::Matrix types to python ndarray and back (vector_list.hpp):
#ifndef VECTOR_PYLIST_HH
#define VECTOR_PYLIST_HH
#include<iostream>
#include<vector>
#include<boost/python.hpp>
#include<Eigen/Dense>
#include<typeinfo>
#include<boost/python/numpy.hpp>
namespace myutil {
template<class T>
boost::python::list to_py_list(Eigen::Matrix<T, Eigen::Dynamic,Eigen::Dynamic> matrix)
{
boost::python::list list;
boost::python::list helplist;
if (matrix.cols() > 1) {
for (int j = 0; j < matrix.cols(); j++) {
helplist = to_py_list<T>(matrix.col(j));
list.append(helplist);
}
} else {
for (int i = 0; i < matrix.rows(); i++) {
list.append(matrix(i,0));
}
}
return list;
}
template<class T>
boost::python::numpy::ndarray to_py_array(Eigen::Matrix<T, Eigen::Dynamic,Eigen::Dynamic> matrix)
{
int cols = matrix.cols();
int rows = matrix.rows();
boost::python::tuple tu = boost::python::make_tuple(rows,cols);
boost::python::numpy::dtype dtype = boost::python::numpy::dtype::get_builtin<T>();
boost::python::numpy::ndarray arr = boost::python::numpy::empty(tu, dtype);
for (int i; i < rows; i++) {
for (int j = 0; j < cols; j++) {
arr[i][j] = matrix(i,j);
}
}
return arr;
}
#endif
My test programme (eigen_ndarray_eigen.cpp) looks as follows:
#include<vector_list.hpp>
#include<iostream>
#include<typeinfo>
int main()
{
Py_Initialize();
np::initialize();
Eigen::Matrix<double,3,2> m;
m << 1,2,3,4,5,6;
std::cout<<m<<std::endl;
boost::python::numpy::ndarray l = myutil::to_py_array<double>(m);
Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> n = myutil::to_eigen<double>(l);
std::cout<<n<<std::endl;
return 0;
}
And my CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project(myutil)
set(CMAKE_BUILD_TYPE "Debug")
set(BOOST_ROOT "$ENV{BOOST_ROOT}")
find_package(PythonLibs 2.7 REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
find_package(Boost 1.61.0 COMPONENTS python REQUIRED)
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
include_directories(${Boost_INCLUDE_DIR} include)
add_executable(test_eigen_ndarray_eigen test/eigen_ndarray_eigen.cpp)
target_link_libraries(test_eigen_ndarray_eigen Eigen3::Eigen ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
I get an error when compiling:
[ 50%] Building CXX object CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o
[100%] Linking CXX executable test_eigen_ndarray_eigen
CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o:In function `boost::python::numpy::ndarray myutil::to_py_array<double>(Eigen::Matrix<double, -1, -1, 0, -1, -1>)':
/home/usr/devel/myutil/include/vector_list.hpp:70: undefined reference to `boost::python::numpy::empty(boost::python::tuple const&, boost::python::numpy::dtype const&)'
CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o: In function `boost::python::numpy::detail::builtin_dtype<double, false>::get()':
/usr/include/boost/python/numpy/dtype.hpp:98: undefined reference to `boost::python::numpy::dtype boost::python::numpy::detail::get_float_dtype<64>()'
collect2: error: ld returned 1 exit status
CMakeFiles/test_eigen_ndarray_eigen.dir/build.make:96: recipe for target 'test_eigen_ndarray_eigen' failed
make[2]: *** [test_eigen_ndarray_eigen] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/test_eigen_ndarray_eigen.dir/all' failed
make[1]: *** [CMakeFiles/test_eigen_ndarray_eigen.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
It's clearly a linking problem but I am already linking my executable against all boost libraries, and I can't figure out what might be wrong. Has anyone experienced something similar? Any tips?
Thanks for your input.
Edit: I was asked for the full error message when compiled with VERBOSE=1:
/usr/bin/cmake -H/home/usr/devel/myutil -B/home/usr/devel/myutil/build --check-build-system CMakeFiles/Makefile.cmake 1
/usr/bin/cmake -E cmake_progress_start /home/usr/devel/myutil/build/CMakeFiles /home/usr/devel/myutil/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/usr/devel/myutil/build'
make -f CMakeFiles/test_eigen_ndarray_eigen.dir/build.make CMakeFiles/test_eigen_ndarray_eigen.dir/depend
make[2]: Entering directory '/home/usr/devel/myutil/build'
cd /home/usr/devel/myutil/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/usr/devel/myutil /home/usr/devel/myutil /home/usr/devel/myutil/build /home/usr/devel/myutil/build /home/usr/devel/myutil/build/CMakeFiles/test_eigen_ndarray_eigen.dir/DependInfo.cmake --color=
Dependee "../include/vector_list.hpp" is newer than depender "CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o".
Clearing dependencies in "/home/usr/devel/myutil/build/CMakeFiles/test_eigen_ndarray_eigen.dir/depend.make".
Scanning dependencies of target test_eigen_ndarray_eigen
make[2]: Leaving directory '/home/usr/devel/myutil/build'
make -f CMakeFiles/test_eigen_ndarray_eigen.dir/build.make CMakeFiles/test_eigen_ndarray_eigen.dir/build
make[2]: Entering directory '/home/usr/devel/myutil/build'
[ 50%] Building CXX object CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o
/usr/bin/c++ -I/usr/include/python2.7 -I/home/usr/devel/myutil/include -isystem /home/usr/devel/src/eigen-git-mirror -g -o CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o -c /home/usr/devel/myutil/test/eigen_ndarray_eigen.cpp
[100%] Linking CXX executable test_eigen_ndarray_eigen
/usr/bin/cmake -E cmake_link_script CMakeFiles/test_eigen_ndarray_eigen.dir/link.txt --verbose=1
/usr/bin/c++ -g CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o -o test_eigen_ndarray_eigen -rdynamic -lboost_python -lpython2.7
CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o: In function `boost::python::numpy::ndarray myutil::to_py_array<double>(Eigen::Matrix<double, -1, -1, 0, -1, -1>)':
/home/usr/devel/myutil/include/vector_list.hpp:70: undefined reference to `boost::python::numpy::empty(boost::python::tuple const&, boost::python::numpy::dtype const&)'
CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o: In function `boost::python::numpy::detail::builtin_dtype<double, false>::get()':
/usr/include/boost/python/numpy/dtype.hpp:98: undefined reference to `boost::python::numpy::dtype boost::python::numpy::detail::get_float_dtype<64>()'
collect2: error: ld returned 1 exit status
CMakeFiles/test_eigen_ndarray_eigen.dir/build.make:96: recipe for target 'test_eigen_ndarray_eigen' failed
make[2]: *** [test_eigen_ndarray_eigen] Error 1
make[2]: Leaving directory '/home/usr/devel/myutil/build'
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/test_eigen_ndarray_eigen.dir/all' failed
make[1]: *** [CMakeFiles/test_eigen_ndarray_eigen.dir/all] Error 2
make[1]: Leaving directory '/home/usr/devel/myutil/build'
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
`'
I checked some answers regarding similar problems (here). Apparently boost_numpy doesn't call the right libraries automatically and sometimes you have to include them manually:
#define BOOST_LIB_NAME "boost_numpy"
#include <boost/config/auto_link.hpp>
I tried this but it didn't work for me...
A while ago I installed MingW to learn C++ with NetBeans, but until now I didn't find the time. Now I created a new C++ project, made a Hello World program with std::cout and it worked immediately. Then I tried to write a file, but it failed:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char** argv) {
cout << "test" << endl;
fstream f;
f.open("a.txt", fstream::in | fstream::out | fstream::trunc);
f << "out" << endl;
f.close();
return 0;
}
lumosc (Build, run):
cd 'D:\<My name>\Programmierung\NetBeans Projects\lumosc_1\lumosc'
D:\Programme\MinGW\msys\1.0\bin\make.exe -f Makefile CONF=Debug
"/D/Programme/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/d/<My name>/Programmierung/NetBeans Projects/lumosc_1/lumosc'
"/D/Programme/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW_1-Windows/lumosc.exe
make.exe[2]: Entering directory `/d/<My name>/Programmierung/NetBeans Projects/lumosc_1/lumosc'
mkdir -p build/Debug/MinGW_1-Windows
rm -f "build/Debug/MinGW_1-Windows/main.o.d"
g++ -c -g -MMD -MP -MF "build/Debug/MinGW_1-Windows/main.o.d" -o build/Debug/MinGW_1-Windows/main.o main.cpp
mkdir -p dist/Debug/MinGW_1-Windows
g++ -o dist/Debug/MinGW_1-Windows/lumosc build/Debug/MinGW_1-Windows/main.o
make.exe[2]: Leaving directory `/d/<My name>/Programmierung/NetBeans Projects/lumosc_1/lumosc'
make.exe[1]: Leaving directory `/d/<My name>/Programmierung/NetBeans Projects/lumosc_1/lumosc'
Output (Note that cout << "test" << endl; wasn't executed):
RUN FAILED (exit value -1.073.741.511, total time: 64ms)
I didn't see any error message. However, when I started the newly created lumosc.exe manually, the following window popped up:
(Translated: Entry point not found - The procedure entry point "__gxx_personality_v0" was not found in the "libstdc++-6.dll" DLL.)
Here's some information about my MingW installation:
I'm completely new to this topic and I hope somebody can help me out!
I have installed PocketSphinx on Ubuntu 14 and now trying to create simple sample. I took code from official website Sphinx.
#include <pocketsphinx.h>
int
main(int argc, char *argv[])
{
ps_decoder_t *ps;
cmd_ln_t *config;
FILE *fh;
char const *hyp, *uttid;
int16 buf[512];
int rv;
int32 score;
config = cmd_ln_init(NULL, ps_args(), TRUE,
"-hmm", MODELDIR "/en-us/en-us",
"-lm", MODELDIR "/en-us/en-us.lm.dmp",
"-dict", MODELDIR "/en-us/cmudict-en-us.dict",
NULL);
if (config == NULL)
return 1;
ps = ps_init(config);
if (ps == NULL)
return 1;
fh = fopen("goforward.raw", "rb");
if (fh == NULL)
return -1;
rv = ps_start_utt(ps);
if (rv < 0)
return 1;
while (!feof(fh)) {
size_t nsamp;
nsamp = fread(buf, 2, 512, fh);
rv = ps_process_raw(ps, buf, nsamp, FALSE, FALSE);
}
rv = ps_end_utt(ps);
if (rv < 0)
return 1;
hyp = ps_get_hyp(ps, &score);
if (hyp == NULL)
return 1;
printf("Recognized: %s\n", hyp);
fclose(fh);
ps_free(ps);
cmd_ln_free_r(config);
return 0;
}
And Qmake is
QT += core
QT -= gui
TARGET = OpenCVQt
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
DEPENDPATH += /usr/local/lib
INCLUDEPATH += /usr/local/include
INCLUDEPATH += /usr/local/include/pocketsphinx
INCLUDEPATH += /usr/local/include/sphinxbase
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
LIBS +=-lpocketsphinx
LIBS += -lsphinxbase
LIBS += -lsphinxad
SOURCES += main.cpp
Can't understand what is wrong. I saw sphinx_config.h in /usr/local/include/sphinxbase. Thanks.
18:54:06: Starting: "/usr/bin/make"
/home/warezovvv/Qt/5.4/gcc_64/bin/qmake -spec linux-g++ CONFIG+=debug -o Makefile ../OpenCVQt/OpenCVQt.pro
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_CORE_LIB -I../OpenCVQt -I. -I/usr/local/include -I/usr/local/include/pocketsphinx -I/usr/local/include/sphinxbase -I../../../Qt/5.4/gcc_64/include -I../../../Qt/5.4/gcc_64/include/QtCore -I. -I../../../Qt/5.4/gcc_64/mkspecs/linux-g++ -o main.o ../OpenCVQt/main.cpp
In file included from /usr/include/sphinxbase/cmd_ln.h:66:0,
from /usr/local/include/pocketsphinx/pocketsphinx.h:52,
from ../OpenCVQt/main.cpp:1:
/usr/include/sphinxbase/prim_type.h:88:27: fatal error: sphinx_config.h: No such file or directory
#include <sphinx_config.h>
^
compilation terminated.
make: *** [main.o] Error 1
18:54:06: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project OpenCVQt (kit: Desktop Qt 5.4.1 GCC 64bit)
When executing step "Make"
18:54:06: Elapsed time: 00:01.
No error with header. Now new error ->
22:42:41: Running steps for project OpenCVQt...
22:42:41: Configuration unchanged, skipping qmake step.
22:42:41: Starting: "/usr/bin/make"
/home/warezovvv/Qt/5.4/gcc_64/bin/qmake -spec linux-g++ CONFIG+=debug -o Makefile ../OpenCVQt/OpenCVQt.pro
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_CORE_LIB -I../OpenCVQt -I. -I/usr/local/include -I/usr/local/include/pocketsphinx -I/usr/local/include/sphinxbase -I/usr/include/sphinxbase -I../../../Qt/5.4/gcc_64/include -I../../../Qt/5.4/gcc_64/include/QtCore -I. -I../../../Qt/5.4/gcc_64/mkspecs/linux-g++ -o main.o ../OpenCVQt/main.cpp
../OpenCVQt/main.cpp: In function 'int main(int, char**)':
../OpenCVQt/main.cpp:14:22: error: 'MODELDIR' was not declared in this scope
"-hmm", MODELDIR "/en-us/en-us",
^
../OpenCVQt/main.cpp:15:30: error: expected ')' before string constant
"-lm", MODELDIR "/en-us/en-us.lm.dmp",
^
../OpenCVQt/main.cpp:16:32: error: expected ')' before string constant
"-dict", MODELDIR "/en-us/cmudict-en-us.dict",
^
../OpenCVQt/main.cpp:9:23: warning: unused variable 'uttid' [-Wunused-variable]
char const *hyp, *uttid;
^
../OpenCVQt/main.cpp: At global scope:
../OpenCVQt/main.cpp:4:1: warning: unused parameter 'argc' [-Wunused-parameter]
main(int argc, char *argv[])
^
../OpenCVQt/main.cpp:4:1: warning: unused parameter 'argv' [-Wunused-parameter]
make: *** [main.o] Error 1
22:42:42: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project OpenCVQt (kit: Desktop Qt 5.4.1 GCC 64bit)
When executing step "Make"
22:42:42: Elapsed time: 00:01.
I solved it with this CMake config:
cmake_minimum_required(VERSION 2.8)
add_definitions(-std=c++11)
find_package(PkgConfig REQUIRED)
pkg_check_modules(POCKETSPHINX REQUIRED pocketsphinx)
pkg_check_modules(SPHINXBASE REQUIRED sphinxbase)
message(STATUS "SPHINXBASE_LIBRARIES => " "${SPHINXBASE_LIBRARIES}")
message(STATUS "POCKETSPHINX_LIBRARIES => " "${POCKETSPHINX_LIBRARIES}")
message(STATUS "POCKETSPHINX_INCLUDE_DIRS => " "${POCKETSPHINX_INCLUDE_DIRS}")
message(STATUS "SPHINXBASE_INCLUDE_DIRS => " "${SPHINXBASE_INCLUDE_DIRS}")
set(
your_pocketsphinx_app_src
your_pocketsphinx_app.cpp
...
)
add_executable(your_pocketsphinx_app your_pocketsphinx_app.cpp)
set_property(TARGET your_pocketsphinx_app PROPERTY CXX_STANDARD 11)
target_include_directories(your_pocketsphinx_app PUBLIC ${POCKETSPHINX_INCLUDE_DIRS})
target_include_directories(your_pocketsphinx_app PUBLIC ${SPHINXBASE_INCLUDE_DIRS})
target_compile_options(your_pocketsphinx_app PUBLIC ${POCKETSPHINX_CFLAGS_OTHER})
target_compile_options(your_pocketsphinx_app PUBLIC ${SPHINXBASE_CFLAGS_OTHER})
target_link_libraries(your_pocketsphinx_app ${SPHINXBASE_LIBRARIES})
target_link_libraries(your_pocketsphinx_app ${POCKETSPHINX_LIBRARIES})
# Binary to be installed.
install(TARGETS your_pocketsphinx_app DESTINATION bin)
You seem to have installation of sphinxbase headers in /usr/include, not in /usr/local/include. If you intentionally compiled sphinxbase this way, you need to add -I/usr/include/sphinxbase in Makefile, not -I/usr/local/include/sphinxbase.
Overall pocketsphinx-5prealpha requires sphinxbase-5prealpha and default installation prefix for them is /usr/local. I suggest you to remove sphinxbase from /usr.
I've got the following code in C++
if (should_run_make) {
std::string make = "make -C ";
make.append(outdir);
std::cout << "Make cmd is " << make << std::endl;
system(make.c_str());
}
This reports the following:
Make cmd is make -C /home/hamiltont/temp/ make: Entering directory
/home/hamiltont/temp' make: *** No targets. Stop.
make: Leaving directory/home/hamiltont/temp'
However, doing it manually works fine in multiple ways e.g.
[hamiltont#4 generator]$ make -C /home/hamiltont/temp/
make: Entering directory `/home/hamiltont/temp'
g++ -O3 -I/usr/include/openmpi-x86_64 -L/usr/local/lib -L/usr/lib64/openmpi/lib -lmpi -lmpi_cxx -lboost_serialization -lboost_mpi stg_impl.cpp -o impl
make: Leaving directory `/home/hamiltont/temp'
[hamiltont#4 generator]$ cd /home/hamiltont/temp/
[hamiltont#4 temp]$ make
g++ -O3 -I/usr/include/openmpi-x86_64 -L/usr/local/lib -L/usr/lib64/openmpi/lib -lmpi -lmpi_cxx -lboost_serialization -lboost_mpi stg_impl.cpp -o impl
Are you generating the makefile from within your C program? That's the only reason I could imagine would cause that specific error message.
make: *** No targets. Stop.
Reproducing the error
Here's how I could generate that message:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp = fopen("Makefile", "w");
fputs("all:\n\techo Done.\n", fp);
system("make");
fclose(fp);
return 0;
}
This, predictably, prints:
make: *** No targets. Stop.
I say predictably because Makefile will be empty! This is because IO is buffered...
Fixed version
So, I close the file before calling system(), which flushes the buffer (fflush() would also do the trick):
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp = fopen("Makefile", "w");
fputs("all:\n\techo Done.\n", fp);
fclose(fp);
system("make");
return 0;
}
Output:
echo Done.
Done.
I used C's IO functions for clarity, but the same rules apply to <iostream>.