Compiling C++ project with qt, portaudio and FLAC - c++

I'm trying to compile a project (swac-record) that relies on qt, portaudio and FLAC. I'm on Mac OS X.
This is what I've got so far:
qmake swac-record-0.4 // This creates a Makefile at the same level as the project and .pro and .qrc files inside the project.
qmake swac-record-0.4/swac-record.pro // not sure what this does exactly
make // will compile the whole project
...but then compilation fails because some symbols cannot be resolved.
Undefined symbols for architecture x86_64:
"_FLAC__StreamDecoderErrorStatusString", referenced from:
DecoderFlac::error_callback(FLAC__StreamDecoderErrorStatus) in codec_flac.o
"_FLAC__StreamDecoderInitStatusString", referenced from:
DecoderFlac::decode(Channel&) in codec_flac.o
"_FLAC__metadata_object_new", referenced from:
EncoderFlac::setTag(Tag const&) in codec_flac.o
"_FLAC__metadata_object_vorbiscomment_append_comment", referenced from:
EncoderFlac::setTag(Tag const&) in codec_flac.o
"_FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair", referenced from:
EncoderFlac::setTag(Tag const&) in codec_flac.o
I don't really have experience with C++. Anyway, my understanding of it is that compilation fails because it cannot find the FLAC library.
The project's website says it uses Flac++ (libflac++-dev) and it is referenced like so in the code:
#include <FLAC++/decoder.h>
#include <FLAC++/encoder.h>
My questions then become:
How can I install libflac++? (Is it not included in flac already installed on the Mac?)
How can I link to libflac++?
I haven't had much luck researching this question (the closest I got is this question but I'm not using Xcode.)
EDIT: as ddriver's advised, I've built libflac myself and added it to the project.
Building libflac: I got the source code and compiled it using ./configure && make && make check && make install. As far as I can tell it went fine:
pkg-config --list-all | grep FLAC++
ls /usr/local/lib | grep FLAC
flac++ FLAC++ - Free Lossless Audio Codec Library (C++ API)
libFLAC++.6.dylib
libFLAC++.a
libFLAC++.dylib
libFLAC++.la
Adding it to the project:
I did so by editing swac-record.pro and adding the library like so (this thread helped):
INCLUDEPATH += /usr/local/lib
LIBS += -L"/usr/local/lib" -lFLAC++
However, I'm still getting the same Undefined symbols error. What did I miss?

Related

Why is this symbol undefined for architecture x86_64 when the rest of the library loaded fine?

I'm trying to use an open source library to read wav/mp3 files in c++, but can't get it to compile when I try to use the init function for said library. When I run cmake --build . --config Release I get:
Undefined symbols for architecture x86_64:
"_drwav_init_file", referenced from:
_main in audiotests.cpp.o
ld: symbol(s) not found for architecture x86_64
My run code is incredibly simple at the moment, just trying to interact with this library at all to begin with.
#include "dr_libs/dr_wav.h"
...
int main()
{
drwav m_wavFile;
drwav_init_file(&m_wavFile, "song.wav", NULL);
}
And yet I can't compile this. It fails to build every-time. I must be missing something super obvious... thoughts?
From the documentation of the library you are using:
This is a single file library. To use it, do something like the following in one .c file.
#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"
Looks like you are missing that one. This is a common technique to bundle implementations in one translation unit, and keeping the header (dr_wav.h in this case) clean from these definitions.

Having problem adding Firebase to my C++ project

So I was trying to use C++ Firebase API to store data from my C++ application to google cloud (firebase). That is my whole purpose.
I have written the necessary code for it based on my understanding from this website: https://firebase.google.com/docs/database/cpp/start and this website: https://firebase.google.com/docs/cpp/setup
These websites give you some sort of how can you add firebase API to my C++ application. The header files or Firebase SDK are from the second website.
So I am using iMac and Visual Studio and I tried to run my code but I got these errors:
././include/firebase/./database/database_reference.h:107:25: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
bool is_valid() const override;
^
1 warning generated.
Undefined symbols for architecture x86_64:
"firebase::App::Create(firebase::AppOptions const&)", referenced from:
_main in test-1dd10f.o
"firebase::Variant::Clear(firebase::Variant::Type)", referenced from:
firebase::Variant::set_int64_value(long long) in test-1dd10f.o
firebase::Variant::~Variant() in test-1dd10f.o
"firebase::database::DatabaseReference::SetValue(firebase::Variant)", referenced from:
_main in test-1dd10f.o
"firebase::database::DatabaseReference::~DatabaseReference()", referenced from:
_main in test-1dd10f.o
"firebase::database::Database::GetInstance(firebase::App*, firebase::InitResult*)", referenced from:
_main in test-1dd10f.o
"firebase::database::DatabaseReference::Child(char const*) const", referenced from:
_main in test-1dd10f.o
"firebase::database::Database::GetReference(char const*) const", referenced from:
_main in test-1dd10f.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Incidentally, I had to change some paths of some header files because somehow, when I compile the file, I get an error of "file not found". I mean I believe I am not suppose to change the original path from firebase header files or SDK to what ever I want (maybe I am wrong).
For example, if I have my myapp.cpp file in the same directory as the firebase folder which has all the headers files, I can just add the header file app.h like this #include "firebase/app.h". But some of these header files include other header files which as the following "#include firebase/internal/common.h" and that caused a file not found error for me. So, I had to change these header files path to something like that "#include "../internal/common.h". I don't think this is an issue as well.
I don't have much knowledge of C++. But I think this is an environment issue and I don't know what to do.
I did not follow the steps about Pod (in the website) because I don't know if that is necessary or I don't understand the instructions clearly.
#include <iostream>
#include "./include/firebase/app.h"
#include "./include/firebase/database.h"
using namespace std;
using namespace firebase;
using namespace database;
int main () {
::firebase::AppOptions appOptions = ::firebase::AppOptions();
appOptions.set_api_key("AIzaSyDocIMJCv9ZfPq8ozvkeSc5PlC-X5gW5_k");
appOptions.set_app_id("smarttrafficmonitoring.firebaseapp.com");
appOptions.set_database_url("https://smarttrafficmonitoring.firebaseio.com");
appOptions.set_project_id("smarttrafficmonitoring");
appOptions.set_storage_bucket("smarttrafficmonitoring.appspot.com");
appOptions.set_messaging_sender_id("220108272524");
::firebase::App* app;
app = ::firebase::App::Create(appOptions);
::firebase::database::Database *database = ::firebase::database::Database::GetInstance(app);
firebase::database::DatabaseReference dbref = database->GetReference("intersections");
dbref.Child("intersection").Child("NSLane").Child("mid").SetValue(11);
cout << "It worked";
return 0;
}
For a darwin (macOS) target, you shouldn't need to use cocoapods. Pulling the latest C++ SDK in VSCode, I was able to build your example on my mac. My CMakeLists.txt file (I assume that this is how your project is being setup if you're not using XCode) is:
cmake_minimum_required(VERSION 3.1)
project(test_project)
set(FIREBASE_CPP_SDK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/firebase_cpp_sdk)
add_subdirectory(firebase_cpp_sdk)
add_executable(test_project main.cpp)
target_link_libraries(test_project firebase_app firebase_database)
main.cpp is the file you provided. I put the firebase c++ sources in a directory named firebase_cpp_sdk. I also made a minor change in how you import your headers:
#include <iostream>
#include <firebase/app.h>
#include <firebase/database.h>
Which is specific to how I setup my CMakeLists.txt file.
Important notes that may help:
I was getting linker errors with just add_subdirectory, the set for FIREBASE_CPP_SDK_DIR works around those by making sure I have a proper absolute path for the Firebase CMakeLists.txt file.
In target_link_libraries I make sure to link firebase_app in addition to firebase_database. Without these I get similar linker errors to your own. As for which libraries to link, I referenced the open source repository here:
https://github.com/firebase/firebase-cpp-sdk
One additional note: if you are linking the libraries manually (ie: not via CMake's systems), I noticed that your linker errors specifically reference the x86_64 architecture. CMake seems to prefer the .a files in libs/darwin/universal, so I would try that first, but you can also try the /libs/darwin/x86_64 directory to see if that helps at all.
Hopefully this gets you unstuck!
One final note is that the desktop SDK support is pretty beta, if you do run into bugs after you get setup, feel free to file them on the GitHub bug tracker:
https://github.com/firebase/firebase-cpp-sdk/issues
I hope that all helps.

OSX: Linker error for boost/filesystem with Xcode 8 and C++ 11

This is my first question on SO. Here goes:
I'm trying to use the boost library - specifically the filesystem part - in a C++ project in Xcode 8.
The problem:
Apple Mach-O Linker (ld) Error Group
"boost::filesystem::detail::dir_itr_close(void*&, void*&)", referenced
from:
"boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, boost::system::error_code*)", referenced from:
"boost::filesystem::detail::directory_iterator_increment(boost::filesystem::directory_iterator&, boost::system::error_code*)", referenced from:
"boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
"boost::system::system_category()", referenced from:
"boost::system::generic_category()", referenced from:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The code:
int main(int argc, char *argv[])
{
std::string dir_path = "foo/bar";
if ( !boost::filesystem::exists( dir_path ) ) return false;
boost::filesystem::directory_iterator end_itr; // default construction
yields past-the-end
for ( boost::filesystem::directory_iterator itr( dir_path );
itr != end_itr;
++itr )
{
std::cout << itr->path();
}
return 0;
}
What I've done:
brew install boost --build-from-source --c++11. I read somewhere that passing this --c++11 flag should fix it, and the --build-from-source is required so that the flag is actually passed to the b2 compiler.
#include <boost/filesystem.hpp> in my project.
Added /usr/local/include to my Header Search Paths under Build Settings. (Also tried adding /usr/local/include/boost and /usr/local/include/boost/system there, to no avail. Also, setting the recursive option on any of my Header Search Paths makes Xcode freak out).
Added /usr/local/lib to my Library Search Paths.
Added -lboost_system -lboost_filesystem to my Other Linker Flags. (Also tried adding -lboost_system-mt, which I saw other answers suggesting).
Tried to do what this answer says, but I have no Link Libraries to Binary section in my Build Phases section. Just Target Dependencies and Compile Sources.
By the way, restarting Xcode and/or my laptop didn't work. I read somewhere that someone could get it to work by reinstalling Xcode after having installed boost, but umm.. idk.
Additional information
Just trying to #include <boost/filesystem.hpp> causes the last 2 linker errors (about the boost::system::system_category() and generic_category()) to occur. However, with #include <boost/regex.hpp>, the program will build successfully.
I also successfully installed boost following the steps
here and were able run the programs from the boost/filesystem tutorial.
I took into consideration passing the files I need to work with as argvs[] to my program, but I could be dealing with tens of thousands of files per folder and I suspect that might get ugly.
OS version: 10.12.4
Xcode version: 8.3.2
I am very new to C++ and almost as new to Xcode. I've spent about 8h trying to get this to work.
Thanks a lot for the help!
I got the same error and this is how I fixed it.
Build Settings > Header Search Paths > (Add) /usr/local/include
Build Settings > Library Search Paths > (Add) /usr/local/lib
Build Settings > Other Linker Flags > (Add) -l boost_system -l boost_filesystem
I hope this helps someone.

Linking with BLAS OS X

I am currently trying to compile a program using a library that I'm not very familiar with. When I run the compiler, I get the following output/error:
Undefined symbols for architecture x86_64:
"_cblas_ddot", referenced from:
shark::LDA::train(shark::LinearClassifier<shark::blas::vector<double> >&, shark::LabeledData<shark::blas::vector<double>, unsigned int> const&) in libshark.a(LDA.cpp.o)
shark::LDA::train(shark::LinearClassifier<shark::blas::vector<double> >&, shark::WeightedLabeledData<shark::blas::vector<double>, unsigned int> const&) in libshark.a(LDA.cpp.o)
My current idea is that this is from missing BLAS library, which I just downloaded and compiled (from fortran code?).
The command-line arg for compiling looks like thsi
g++ -o example -I/to/boost/include -I/to/shark/include -L/to/boost/lib -L/to/shark/lib -L/to/BLAS -lshark -lblas -l(boost_flags)
In /to/BLAS have a libblas.a, and I ran nm libblas.a which gives a line
libblas.a(ddot.o):
00000000000001c0 s EH_frame1
0000000000000000 T _ddot_
Without being too secure abut this, I assume that this means that the library does have the symbol, but without the _cblas_ prefix.
What can I do from this point? Can I change the symbols name? Or do I need to link this library with something else?
I use OS X Mavericks
Thanks in advance : )
OS X ships with BLAS (including cblas) already installed (it's part of the Accelerate.framework). There's no need to download and build your own. Just link with -lcblas.
Solution was as suggested by Logicrat, that I needed other files, I downloaded te source code from here and build it with cmake/make very seamless. Linking with the libraries that came from this resolved the issue.

Unable to use Boost in Xcode, keep getting "Undefined symbols for architecture" errors

I'm trying to include Boost in my Xcode project and it seems no matter what I do the project doesn't want to compile.
I get this error every time:
Undefined symbols for architecture x86_64:
"boost::log::v2s_mt_posix::record_view::public_data::destroy(boost::log::v2s_mt_posix::record_view::public_data const*)", referenced from:
boost::log::v2s_mt_posix::record::reset() in Logger.o
"boost::log::v2s_mt_posix::attribute_set::insert(boost::log::v2s_mt_posix::attribute_name, boost::log::v2s_mt_posix::attribute const&)", referenced from:
boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<boost::log::v2s_mt_posix::trivial::severity_level>, boost::log::v2s_mt_posix::sources::single_thread_model>::add_attribute_unlocked(boost::log::v2s_mt_posix::attribute_name const&, boost::log::v2s_mt_posix::attribute const&) in Logger.o
(Along with a bunch of others totally 108 errors.)
I've tried a lot to fix this, and read pretty much every question on StackOverflow that is relevant to this.
I am linking it in "Link Binary With Items", I've got libboost_serialization.a and libboost_system.a there (only things in that list).
After installing Boost manually with the ./b2 command, I dragged both of those files into the sidebar. Therefore, the files are in the same directory as my .xcodeproj.
Under Library Search Paths, I have $(PROJECT_DIR), so it should be able to find them.
Am I compiling it with the wrong flags or something?
This solved the problem for me:
Rather than adding libboost_log-mt.* to the ‘Link Binary With Libraries’ section under the ‘Build Phases’ tab, add a path to the archive file (i.e., the .a; dynamic library doesn't work) in ‘Other Linker Flags’ under the ‘Build Settings’ tab:
Other Linker Flags under Build Settings
I have no explanation for why this works; but I've noticed that this technique has worked for me in the past with other libraries ‘not linking’ as well.