undefined reference to Aquila::WaveFile - c++11

I am trying to compile a program using Aquila dsp library.
The code is:
#include "/usr/aquila/include/aquila/source/WaveFile.h"
#include <iostream>
int main(int argc, char *argv[])
{
if (argc < 2)
{
std::cout << "Usage: wave_info <FILENAME>" << std::endl;
return 1;
}
Aquila::WaveFile wav(argv[1]);
std::cout << "Filename: " << wav.getFilename();
std::cout << "\nLength: " << wav.getAudioLength() << " ms";
std::cout << "\nSample frequency: " << wav.getSampleFrequency() << " Hz";
std::cout << "\nChannels: " << wav.getChannelsNum();
std::cout << "\nByte rate: " << wav.getBytesPerSec()/1024 << " kB/s";
std::cout << "\nBits per sample: " << wav.getBitsPerSample() << "b\n";
return 0;
}
The make file is:
MFCC: main.o
g++-5 -Wall -std=c++11 -L/usr/aquila/lib -lOoura_fft -lAquila main.o -o MFCC
main.o: main.cpp
g++-5 -c -Wall -std=c++11 main.cpp
clean:
rm *.o MFCC
When I try to compile it, the following message is showed:
dario#dario-Lenovo-G460:~/Contenidos/HSTM/C++/MFCC$ make
g++-5 -Wall -std=c++11 -L/usr/aquila/lib -lOoura_fft -lAquila main.o -o MFCC
main.o: In function `main':
main.cpp:(.text+0xa4): undefined reference to `Aquila::WaveFile::WaveFile(std::string const&, Aquila::StereoChannel)'
main.cpp:(.text+0x117): undefined reference to `Aquila::WaveFile::getAudioLength() const'
main.cpp:(.text+0x224): undefined reference to `Aquila::WaveFile::~WaveFile()'
main.cpp:(.text+0x28b): undefined reference to `Aquila::WaveFile::~WaveFile()'
collect2: error: ld returned 1 exit status
make: *** [MFCC] Error 1
The nearest forum I found is at: Undefined reference with extern C
I tried to apply all the advices given there, but the error remains.
My OS is:
dario#dario-Lenovo-G460:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
Thanks!

In your Makefile, in the target for MFCC, place the main object file and executable name (MFCC) before the library includes.
Based on the answer from here: c++ undefined references with static library

Related

Dart VM embedding (libdart_jit.a) on MacOS produces "dyld: Symbol not found: __ZN4dart13FLAG_profilerE"

I am trying to make my first C++ app with embedded Dart VM. I have a problem with minimal setup of compiler on my MacOS 10.14.6. My build is successful, but when I start the app, it crashed with:
$ clang++ -I ${HOME}/opt/dart-sdk --define-macro DART_SHARED_LIB=1 -L ./libs/debug -ldart_jit -lm -lz -O2 -undefined dynamic_lookup -o reproduce *.cpp
$ ./reproduce
dyld: Symbol not found: __ZN4dart13FLAG_profilerE
Although symbol __ZN4dart13FLAG_profilerE presents inside binary
$ nm reproduce | grep __ZN4dart13FLAG_profilerE
U __ZN4dart13FLAG_profilerE
How to compile/link this properly?
My reproduce program is:
#include <iostream>
#include <include/dart_api.h>
int main(int argc, const char * argv[]) {
char* setVMFlagsError = Dart_SetVMFlags(argc, argv);
if (setVMFlagsError != nullptr) {
std::cerr << "Error while set Dart VM flags: " << setVMFlagsError << "\n";
::free(setVMFlagsError);
return 1;
} else {
Dart_InitializeParams params = {};
std::cout << "Hello, World!\n";
return 0;
}
}
Dart SDK was built following by official documentation
(dart-sdk-pyenv) ~/tmp/dart-sdk/sdk $ ./tools/build.py --mode all --arch x64 create_sdk
(dart-sdk-pyenv) ~/tmp/dart-sdk/sdk $ cp -a ~/tmp/dart-sdk/sdk/xcodebuild/DebugX64/dart-sdk ~/opt/

GDB's next command jumps backward to all stack-allocated objects at end of scope

When I have stack-allocated objects in a scope (a set of commands within curly brackets), and I use next at the end of that scope, gdb jumps back to where each of the stack-allocated objects are, in reverse order.
This is disturbing during a debug ritual: When there are a lot of stack-allocated instances of objects, the debugger jumps backward to each one, and only when it is finished does it proceed forward. Instead, I expect it to proceed to the next line after the scope.
Is there a way to configure gdb to not do that, or is this some flag that I need to pass to gcc when I'm building?
At first, I thought it was that I was compiling using -O0 or something (GDB jumps to wrong lines in out of order fashion), but that is not the case here.
Here is how I am building:
/opt/rh/devtoolset-6/root/usr/bin/c++ -MD -DDEBUG -g -ggdb -gstabs+ -fPIC -Wall -Werror -Wsynth -Wno-comment -Wreturn-type main.cpp -c -o main.o
/opt/rh/devtoolset-6/root/usr/bin/c++ -MD -DDEBUG -g -ggdb -gstabs+ -fPIC -Wall -Werror -Wsynth -Wno-comment -Wreturn-type main.o -L. -L/opt/rh/devtoolset-6/root/usr/lib64 -lstdc++ -o main.exe
Below is what I'm seeing in the debugger. Notice the version of GDB involved:
bash-4.2$ gdb main.exe
GNU gdb (GDB) Red Hat Enterprise Linux 7.12.1-48.el6
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from main.exe...done.
(gdb) b main
Breakpoint 1 at 0x400a27: file main.cpp, line 45.
(gdb) r
Starting program: /home/brentg/scratch_sandboxes/cxxminimal/main.exe
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.192.el6.x86_64
Breakpoint 1, main (argc=1, argv=0x7fffffffeb38, envp=0x7fffffffeb48)
at main.cpp:45
45 std::cout << __FILE__ << ":" << __LINE__ << ":" << "main begin" << std::endl;
Missing separate debuginfos, use: debuginfo-install libgcc-4.4.7-17.el6.x86_64 libstdc++-4.4.7-17.el6.x86_64
(gdb) l
40 std::cout << __FILE__ << ":" << __LINE__ << ":" << "printing some info 2" << std::endl;
41 }
42
43 int main(int argc, char *argv[], char *const envp[])
44 {
45 std::cout << __FILE__ << ":" << __LINE__ << ":" << "main begin" << std::endl;
46 some_function_that_uses_Foo();
47 std::cout << __FILE__ << ":" << __LINE__ << ":" << "main end" << std::endl;
48 return 0;
49 } // end main
(gdb) n
main.cpp:45:main begin
46 some_function_that_uses_Foo();
(gdb) s
some_function_that_uses_Foo () at main.cpp:38
38 std::cout << __FILE__ << ":" << __LINE__ << ":" << "printing some info 1" << std::endl;
(gdb) n
main.cpp:38:printing some info 1
39 Foo the_foo1;
(gdb) n
40 std::cout << __FILE__ << ":" << __LINE__ << ":" << "printing some info 2" << std::endl;
(gdb) l
35
36 void some_function_that_uses_Foo()
37 {
38 std::cout << __FILE__ << ":" << __LINE__ << ":" << "printing some info 1" << std::endl;
39 Foo the_foo1;
40 std::cout << __FILE__ << ":" << __LINE__ << ":" << "printing some info 2" << std::endl;
41 }
42
43 int main(int argc, char *argv[], char *const envp[])
44 {
(gdb) n
main.cpp:40:printing some info 2
39 Foo the_foo1;
At this point, I wonder: Why am I now back on line 39? When I was on line 40, entering in "next", then it seemingly jumps backwards.
Looking at the gdb manual for the "next" command, I do not see anything in regards to C++ constructors/destructors.
/opt/rh/devtoolset-6/root/usr/bin/c++ -MD -DDEBUG -g -ggdb -gstabs+ ...
You may be suffering from self-inflicted wounds.
The STABS debugging format is ancient, and should not be used on any system less than 15 years old. It is also totally inadequate and completely untested.
libgcc-4.4.7-17.el6.x86_64
You are also using ancient GCC-4.4.7, which was released in March of 2012. You will likely get better debugging experience using a more modern version.

Make is not recognizing my library!

I am trying to create a program in C++ that utilizes the rudeconfig library.
I run make, and get this:
g++ -o Homework5_executable helloworld.o -lrudeconfig -L/home/j/je/jea160530/hw5/libs
/bin/ld: cannot find -lrudeconfig
collect2: error: ld returned 1 exit status
make: *** [Homework5_executable] Error 1
I know this is happening because make is not recognizing the rudeconfig library, however I have followed the instructions on the rudeconfig site for install correctly.
Here is the code:
Makefile
#
# Set up info for C++ implicit rule
CXX = g++
CXXFLAGS = -Wall
CPPFLAGS = -I/home/012/j/je/jea160530/hw5/include
#
# Set up any Linker Flags
LDFLAGS = -L/home/012/j/je/jea160530/hw5/libs
#
# Set up libraries needer for compilation
LDLIBS = -lrudeconfig
#
# We choose the project name. This is used in building the file name for the backup target
PROJECTNAME = JesseAlotto_Homework5
#
# We choose the source files to include and name the output
SRCS = helloworld.cc
#
# We choose the name of the executable to be created
EXEC = Homework5_executable
#
# NORMALLY DON'T NEED TO CHANGE ANYTHING BELOW HERE
# =================================================
#
OBJS = $(SRCS:cc=o)
all: $(EXEC)
clean:
rm -f $(OBJS) *.d *~ \#* $(EXEC)
Makefile: $(SRCS:.cc=.d)
# Pattern for .d files.
# =====================
%.d:%.cc
#echo Updating .d Dependency File
#set -e; rm -f $#; \
$(CXX) -MM $(CPPFLAGS) $< > $#.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $# : ,g' < $#.$$$$ > $#; \
rm -f $#.$$$$
# This is a rule to link the files. Pretty standard
# ================================================
$(EXEC): $(OBJS)
$(CXX) -o $(EXEC) $(OBJS) $(LDFLAGS) $(LDLIBS)
#echo Program compiled succesfully!
#
# Backup Target
# =============
backup: clean
#mkdir -p ~/backups; chmod 700 ~/backups
#$(eval CURDIRNAME := $(bash pwd))
#$(eval MKBKUPNAME := ~/backups/$(PROJECTNAME)-$(shell date +'%Y.%m.%d-%H:%M:%S').tar.gz)
#echo
#echo Writing Backup file to: $(MKBKUPNAME)
#echo
#tar -zcvf $(MKBKUPNAME) ./$(CURDIRNAME)
#chmod 600 $(MKBKUPNAME)
#echo
#echo Done!
#
# Include the dependency files
# ============================
-include $(SRCS:.cc=.d)
helloworld.cc
#include <string>
#include <iostream>
#include <fstream>
#include <tclap/CmdLine.h>
#include <map>
#include <stdlib.h>
#include <rude/config.h>
using namespace rude;
int main(int argc, char *argv[]){
std::string nextLine;
std::map<int, std::string> optionMap;
try{
std::cout << "hello world!";
//Command Line Variable
TCLAP::CmdLine cmd("CS3377.002 Program 5", ' ', "1.0");
//Switch Args
TCLAP::SwitchArg daemonSwitch("d", "daemon", "Run in daemon mode (forks to run as a daemon).", cmd, false);
//Unlabeled Value Args
TCLAP::UnlabeledValueArg<std::string> infileArg("infile", "The name of the configuration file. Defaults to cs3376dirmond.conf", true, "cs3376dirmond.conf", "config filename", false);
//Add leftover flags to cmdLine object
cmd.add(infileArg);
//Parse the command line
cmd.parse(argc, argv);
//Create an enumeratedlist for the mapping
enum flags {DAEMON, INFILE};
//Map keys and values to map
if (daemonSwitch.getValue()){
optionMap[DAEMON] = "1";
}
else{
optionMap[DAEMON] = "0";
}
optionMap[INFILE] = infileArg.getValue();
//Load input file
std::ifstream inputFile;
inputFile.open(optionMap[INFILE].c_str(), std::ios::in);
if(!inputFile){
std::cerr << "Error: no input file" << std::endl;
}
//============================================PARSE CONFIGURATION FILE==========================
Config config;
config.load("cs3376dirmond.conf");
//==============================================================================================
inputFile.close();
return 0;
} catch (TCLAP::ArgException &e) //catch any exceptions
{ std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;}
}
The error is caused by this command:
g++ -o Homework5_executable helloworld.o -lrudeconfig -L/home/j/je/jea160530/hw5/libs
not by make itself.
The error means that the linker isn’t finding librudeconfig.so in the library search path. From your comments, it turns out the library is named rudeconfig.so instead, so you need to specify
LDLIBS = -l:rudeconfig.so
instead of -lrudeconfig (which always expands to librudeconfig.so or librudeconfig.a).
Ideally, the library should be installed as librudeconfig.so...

How can I create and use a Makefile on Windows?

I know how to write Makefiles for Linux, and was hoping it would be similar in Windows. However, from what I've seen on the internet, it is quite difficult.
If I have one file main.cpp, what would be the simplest form of a Makefile? Also, what would be the command to make Makefile ?
Thanks!
In brief...
$ ls && cat main.cpp && cat Makefile && make && ./main
Makefile main.cpp
/* main.cpp */
#include <iostream>
int main(int, char **) {
std::cout << __func__ << "#" << __FILE__ << ":" << __LINE__ << std::endl;
return EXIT_SUCCESS;
}
# Makefile
all: main
clean: ; rm -f main
g++ main.cpp -o main
main#main.cpp:4
$
That's as bare-bones as I can make it.

error: expected expression when using lambda expression in C++

When using a lambda expression my compiler shows me an error. This is the implementation (where name is a std::string&):
auto expression = [name](const Item* x) -> bool { return x->get_name() == name; };
This is the error:
items/container.cpp:20:27: error: expected expression
auto expression = [name](const Item* x) -> bool { return x->get_name() == name; };
These are my compiler flags:
CFLAGS=$(-std=c++11 -stdlib=libc++ -g -Wall -Werror -Wextra -I.)
All other C++11 features I have used have worked so far. I am using MacOS 10.11.3.
>> clang --version
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.3.0
Thread model: posix
>> clang++ --version
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.3.0
Thread model: posix
Unfortunately this did not help me: Clang 3.1 and C++11 support status
UPDATE: After creating a minimal example as suggested by the comments below it worked! The problem must lie in my makefile. This reproduces the error:
CC=clang++
CFLAGS=$(-stdlib=libc++ -std=c++11 -g -Wall -Werror -Wextra -I.)
all: main
main: main.o
$(CC) $(CFLAGS) -o main *.o
main.o: main.cpp
$(CC) $(CFLAGS) -c main.cpp
My main.cpp file:
#include <iostream>
#include <string>
int main() {
auto lambda = [](const std::string& str) { return str == "whatever"; };
std::string s1 = "something else";
std::string s2 = "whatever";
std::cout << "should be false: " << lambda(s1) << std::endl;
std::cout << "should be true: " << lambda(s2) << std::endl;
return 0;
}
You're misusing the $ sign in your makefile. It's for substitutions of variables so $(-stdlib=libc++ ...) would suggest you had a variable whose name started with -stdlib=... (I'm surprised this isn't giving you an error)
If you don't want a substitution and just want literal content, write it after the = sign unescaped:
CC=clang++
CFLAGS=-stdlib=libc++ -std=c++11 -g -Wall -Werror -Wextra -I.
all: main
main: main.o
$(CC) $(CFLAGS) -o main *.o
main.o: main.cpp
$(CC) $(CFLAGS) -c main.cpp

Resources