OSX Disk Arbitration linker errors - c++

Trying to compile my C++ application using clang which works but I get the following linker error:
Undefined symbols for architecture x86_64:
"_DADiskCopyDescription", referenced from:
Security::getHddID() in Security.cpp.o
"_DADiskCreateFromBSDName", referenced from:
Security::getHddID() in Security.cpp.o
"_DASessionCreate", referenced from:
Security::getHddID() in Security.cpp.o
ld: symbol(s) not found for architecture x86_64
I've checked the official documentation for Disk Arbitration on the Apple website but that's awful, since it doesn't even tell you which library file to include, let alone what to link to.
I'm using CMake to set up my build chain.

You need to use -framework DiskArbitration in your linker arguments.

Related

Xcode 8 - c++ - Undefined symbols for architecture x86_64: "liblas::Reader....."

I am currently working on a c++ project using xcode 8, and I keep getting this error:
Undefined symbols for architecture x86_64:
"liblas::Reader::Reader(std::__1::basic_istream<char, std::__1::char_traits<char> >&)", referenced from:
_main in main.o
"liblas::Reader::~Reader()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have compiled boost, liblas, etc. I have it included in my cmakelists.txt as well, and have the folder it is included in listed in 'Framework Search Paths' as well as 'Header Search Paths'. My compiler is the xcode 8 default of Apple LLVM 8.0. My deployment target is 10.11. The valid architectures are 'x86_64' and 'i386'.
Here is the code that attempts to use libLAS (file.las contains a hardcoded path to my las file). This code was pulled directly off the libLAS c++ tutorial here:
std::ifstream ifs;
ifs.open("file.las", std::ios::in | std::ios::binary);
liblas::ReaderFactory f;
liblas::Reader reader = f.CreateWithStream(ifs);
If I comment out the line liblas::Reader reader = f.CreateWithStream(ifs);, the code compiles fine, and produces a valid executable. With this line here, it throws the error. I need to be able to read LAS files with this project however, so I need to try to get the Reader to work.
So my questions are:
Is there a better way to debug this?
Is this an obvious error that I'm missing?
Is this an issue with the library? (libLAS)
What can I do to get this working?
Thanks to anyone in advance!

Linker Error in Xcode 8.1 when trying to build UETorch

I've been trying to build UETorch for OSX 10.12 using Xcode and have encountered the following error:
Undefined symbols for architecture x86_64:
"FlushRenderingCommands()", referenced from:
_CaptureScreenshot in Module.UETorch.cpp.o
InitCapture(UObject*, IntSize const*, FViewport**, APlayerController**, UWorld**, FSceneView**) in Module.UETorch.cpp.o
"FSlateApplication::CurrentApplication", referenced from:
_CaptureScreenshot in Module.UETorch.cpp.o
FSlateApplication::Get() in Module.UETorch.cpp.o
"FSlateApplication::TakeScreenshot(TSharedRef<SWidget, (ESPMode)0> const&, FIntRect const&, TArray<FColor, FDefaultAllocator>&, FIntVector&)", referenced from:
_CaptureScreenshot in Module.UETorch.cpp.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 seems like the ld: symbol(s) not found... part is often fixed by using libstdc++ instead of libc++ and I have tried adding -stdlib=libstdc++ to "Other Linker Flags" as well as linking libstdc++.6.0.9.dylib in the Build Phases section but I am still getting the same error.
I don't have the reputation to comment hence adding it here, you get undefined symbols when you try to use the symbol/Call the function and the linker can not find its definition. So if the definition is from some library then add it during your linking stage.
You can check if the definition is present or not in the library by using nm command, e.g. "nm -D"

linking Boost library to Xcode project

I'm trying to create a project that uses the Boost library. I'm on OS X 10.9.5 (I should update that) and using Xcode 6.2. I installed boost with homebrew brew install boost and it's located in /usr/local/Cellar/boost/1.59.0. I added the path the the /usr/local/Cellar/boost/1.59.0/include to the header search path in Xcode and it seems to recognize it because the autocomplete hinting works.
In the boost documentation it mentions that some of the Boost libraries must be built before they can be used. I assume homebrew took care of that because I have a bunch of .a and .dylib files in /usr/local/Cellar/boost/1.59.0/lib
I'm still new to C++ and the Xcode build process but it seems I still need to link the compiled libraries to my project. I tried adding the path /usr/local/Cellar/boost/1.59.0/lib to my project's library search paths but I'm not sure if that is correct.
Here is the error I get when I try to build my project.
Undefined symbols for architecture x86_64:
"boost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
boost::filesystem::create_directory(boost::filesystem::path const&) in main.o
"boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
boost::filesystem::exists(boost::filesystem::path const&) in main.o
"boost::system::system_category()", referenced from:
___cxx_global_var_init2 in main.o
"boost::system::generic_category()", referenced from:
___cxx_global_var_init in main.o
___cxx_global_var_init1 in main.o
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 else I need to configure to get this to work?
Adding the path is correct but you also need to specify the libraries you need. On the commandline you would use -l for that in Xcode you can add them to Other Linker Flags.
The libraries you need are boost_filesystem and boost_system.

Issue compiling Go program when linking to a compiled version of zeromq on Mac

I've compiled ZeroMQ on Mac OSX 10.9.5 in order to then link to a simple Go program using github.com/pebbe/zmq4, but I'm getting this error I don't understand or know exactly how to remedy.
# github.com/pebbe/zmq4
ld: warning: ignoring file /usr/local/lib/libzmq.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/lib/libzmq.dylib
Undefined symbols for architecture i386:
"_zmq_bind", referenced from:
__cgo_59814aec404b_C2func_zmq_bind in zmq4.cgo2.o
__cgo_59814aec404b_Cfunc_zmq_bind in zmq4.cgo2.o
(maybe you meant: __cgo_59814aec404b_Cfunc_zmq_bind, __cgo_59814aec404b_C2func_zmq_bind )
"_zmq_close", referenced from:
__cgo_59814aec404b_C2func_zmq_close in zmq4.cgo2.o
__cgo_59814aec404b_Cfunc_zmq_close in zmq4.cgo2.o
(maybe you meant: __cgo_59814aec404b_C2func_zmq_close,
...
"_zmq_z85_encode", referenced from:
__cgo_59814aec404b_Cfunc_zmq_z85_encode in zmq4.cgo2.o
(maybe you meant: __cgo_59814aec404b_Cfunc_zmq_z85_encode)
ld: symbol(s) not found for architecture i386
collect2: error: ld returned 1 exit status
I think it makes sense that the dylib is made for x86_64 (the Mac) but why Go is trying to link with i386? How do I control that and make it link differently? or even if it's correct?
If you build libzmq yourself, configure with --disable-shared --enable-static keys. If you use homebrew, uninstall zmq and build the library manually. If you need "fat" universal static library use this script:
https://github.com/drewcrawford/libzmq-ios

Linker errors after changing source file type to Objective-C++

I have an OpenGL ES 2.0 application, and would like to use C++ code in a view controller implementation. However, after changing the file extension to mm (or even just adjust the source type without changing the filename), the following errors are encountered during linking:
Undefined symbols for architecture armv7:
"_GLKMatrix4Identity", referenced from:
GLKMatrix4MakeTranslation(float, float, float) in GameViewController.o
"_OBJC_METACLASS_$_GLKViewController", referenced from:
_OBJC_METACLASS_$_GameViewController in GameViewController.o
"_OBJC_CLASS_$_GLKViewController", referenced from:
_OBJC_CLASS_$_GameViewController in GameViewController.o
"_GLKMatrix3InvertAndTranspose", referenced from:
-[GameViewController update] in GameViewController.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any suggestions are welcome.
I manually added the GLKit framework in build phases settings.
(Interesting question though - why didn't the app require it when no C++ source was involved -- how could it possibly compile and run?)