error on boost filesystem - boost

I try to use boost filesystem on my Mac. I only added the following header and got an error when I tried to compile
# include <boost/filesystem.hpp>
the error is
Undefined symbols for architecture x86_64:
"boost::system::generic_category()", referenced from:
__static_initialization_and_destruction_0(int, int) in cclyDZox.o
"boost::system::system_category()", referenced from:
__static_initialization_and_destruction_0(int, int) in cclyDZox.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
any help is appreciated

You need to add the boost_system library:
-lboost_system
to your build command. Note that you will also need to provide the -lboost_system library too.
If your project thereafter builds but moans with something like
dyld: Library not loaded: libboost_filesystem.dylib
you just need to set the environment variable
DYLD_LIBRARY_PATH
to include your
$BOOST_HOME/lib
directory as mentioned here.

I think you should do
g++ -I~/Documents/boost_1_53_0/include -L~/Documents/boost_1_53_0/stage/lib -std=c++11 test1ver1.cpp -lboost_filesystem -lboost_system
The
-I flag points to where the Boost headers are
-L flag points to where the Boost libs are
-lboost_filesystem and -lboost_system flags enabled the link of your binary and the Boost Filesystem and System shared libraries. (Those should be always after the object or source files)
For instance:
#include <boost/filesystem.hpp>
int main() {
boost::filesystem::path path_household_csv("./test");
}

Related

Compile Fortran Function using gfortran: object file was built for newer macOS version than being linked

Given a very simple fortran (95) function and a very simple c++ call to the program, I should be able to compile the program using:
g++ -c main1.cpp
gfortran -c test.f95
g++ main1.o test.o -o run
However, here I get the following error:
ld: warning: object file (test.o) was built for newer macOS version (11.5) than being linked (11.0)
Undefined symbols for architecture arm64:
"hello_()", referenced from:
_main in main1.o
"__gfortran_st_write", referenced from:
_hello_ in test.o
"__gfortran_st_write_done", referenced from:
_hello_ in test.o
"__gfortran_transfer_character_write", referenced from:
hello in test.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here, adding a -v tag before the -o tag and after the -o tag and the exe run did not solve the problem, as suggested by the error message.

FFMPEG library usage for own C++ project

I would like to create my own project using FFMPEG to build a player, but creating a new file to include ffmpeg library seems not easy. I have configure the ffmpeg and make build.
./configure
./make
The ffmpeg hello world program (myffmpeg.c):
#include <libavformat/avformat.h>
int main(int argc, char *argv[]) {
av_register_all();
return 0;
}
but it shows
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated
Undefined symbols for architecture x86_64:
"av_register_all()", referenced from:
_main in myffmpeg-61ec1b.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation
When I try to link the allformats.o file, which has av_register_all function inside. I got:
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated
Undefined symbols for architecture x86_64:
"_av_register_input_format", referenced from:
_register_all in allformats.o
"_av_register_output_format", referenced from:
_register_all in allformats.o
"_avcodec_register_all", referenced from:
_register_all in allformats.o
"_ff_a64_muxer", referenced from:
_register_all in allformats.o
...
"_ff_yuv4mpegpipe_muxer", referenced from:
_register_all in allformats.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It should be my bad Makefile knowledge, could anyone give me some hint on how to call ffmpeg library functions? Or even how to modify the Makefile to build my own program? Thanks!
*Update:
It could be my compiling command problem, is it the way to compile?
g++ myffmpeg.c
maybe the problem is that c++ is decorating functions. So the same function compiled with C compiler and C++ looks different to linker. try this:
extern "C"
{
#include <libavformat/avformat.h>
}
this code means that you told your compiler to not decorate functions in that file.
I think I could answer myself.
g++ -o main.o main.c `pkg-config --cflags --libs libavformat`
I don't know the reason now, it is from https://soledadpenades.com/2009/11/24/linking-with-ffmpegs-libav/
We still need the extern, see answer below.

JNI build C file (Undefined symbols for architecture x86_64)

I'm trying to build a .c file on OSX but I keep getting:
Undefined symbols for architecture x86_64
#include "Test.h"
JNIEXPORT jint JNICALL Java_Test_test
(JNIEnv * env, jclass cls, jbyteArray s, jlong ss, jbyteArray sss, jlong ssss, jbyteArray sssss, jlong ssssss) {
/*printf("Hello World!\n");*/
return 1;
}
Built with:
clang++ -o test -I/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/include/darwin Test.cpp
Undefined symbols for architecture x86_64: "_main", referenced from:
implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Is there something I need to install?
clang++ -o test Test.cpp is trying to compile and link to produce a runnable executable. You didn't define main(), so of course this fails when it tries to link the CRT code (which calls the user-supplied main().)
Perhaps you meant to use clang++ -fPIC -shared -o libtest.so Test.cpp -I... (keeping all the other options the same), to make a shared library like JNI needs. Or .dylib or .jnilib, whatever libraries are normally called on your platform.
If you're following a tutorial that didn't tell you how to compile your code, it's probably not a very good tutorial and you should find better documentation.

Linking g++ OS X Mavericks

I'm trying to compile a test file which uses the Cmage library (http://cimg.sourceforge.net).
I already generated the .o file but apparently this file uses the X11 Library and I'm having some problems when linking.
If I do this:
g++ -o test CImg_demo.o
I get this:
Undefined symbols for architecture x86_64:
"_XAllocClassHint", referenced from:
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in CImg_demo.o
"_XCheckMaskEvent", referenced from:
cimg_library::CImgDisplay::_events_thread(void*) in CImg_demo.o
etc, etc
If I do this:
g++ -o test CImg_demo.o -lX11
I get this:
ld: library not found for -lX11
collect2: ld returned 1 exit status
As my OS X is mavericks, X11 has been installed with XQuartz in /opt/X11/lib/
So I tried to add that directory where all the .dylib files are at the beginning of the line, like this:
g++ -L/opt/X11/lib/ -o test CImg_demo.o
but I get exactly the same references problem.
Does anyone know how to find out the directory that includes all the object files to correctly make the linking?
Thank you in advance.

Link dynamic library and ffmpeg x86_64 version

I'm working with FFMPEG on Mac OSX, my Mac version is 10.6.8 (i386).
When I try to compile my C++ code linking a dynamic library:
g++ sdk.cpp -rpath /usr/local/lib/libinsight.dylib -o sdk
I get the following error:
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
"av_open_input_file(AVFormatContext**, char const*, AVInputFormat*, int, AVFormatParameters*)", referenced from:
ffmpeg_open(AVFormatContext**, char const*, int*)in ccCkx9dd.o
(so forth fo every FFMPEG call)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Without linking dylib I have no problem. What's the matter?
P.S. ffmpeg version is Mach-O 64-bit executable x86_64
g++ sdk.cpp -rpath /usr/local/lib/libinsight.dylib -o sdk
Shouldn't you be linking to libffmpeg somewhere? Try adding -lffmpeg to your link command line.

Resources