Trouble linking sfml files using g++ - sfml

I downloaded the sfml GCC - 32-bit version for linux; though my operating system is ubuntu. I am able to compile a test program, but when I try to link the libraries I get an error:
dylan#Aspire-one:~/Documents/SFML-2.3.1/projects$ g++ test.o -o sfml-app -L/home/dylan/Documents/SFML-2.3.1/lib -lsfml-graphics -lsfml-window -lsfml-system
/home/dylan/Documents/SFML-2.3.1/lib/libsfml-graphics.so: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)#GLIBCXX_3.4.20'
collect2: error: ld returned 1 exit status
If you have any clues please comment below, but I would appreciate a full answer.

Expanding on my earlier comment: It looks like you have SFML binaries that are linked to a version of glibc that isn't on your system. You need to either install that version of glibc (3.4.20, 32 bit) or get/build SFML binaries that link to a version of glibc that you do have.
The Linux world is different from the Windows and the Mac worlds. And the right way to do things has changed over the years. And my personal willingness to experiment has changed as well.
You generally want to get binaries from the distribution you use. Ubuntu in your case, Fedora in mine. This allows the package manager (e.g., yum or apt-get) to do its job: determine if you have the needed prerequisites when installing new software, uninstall software as desired, install updates with minimal fuss, etc. If you can't get the binaries you want, at least try to find a repository that you can tell your package manager to trust, so that you can get regular updates.
If you aren't able to find an acceptable package that way, your only option is to build from source. Download the latest source code archive from http://www.sfml-dev.org/download.php (get a release with a version number, instead of "whatever's currently in GitHub"). It looks like SFML currently uses CMake, so you'll want to follow the directions on http://www.sfml-dev.org/tutorials/2.3/compile-with-cmake.php to build.
Personally, I wouldn't run the final make install step. That will copy the binaries to /usr/local or some similar place, but won't notify your package manager about the change. And there won't be a way to uninstall aside from manually deleting the files. Instead, just add the folder you build in to your PATH (and the include folder to your INCLUDE_PATH). You'll be able to develop your application with that setup, and nothing will prevent you from installing the package when somebody finally creates it for your distribution.

Related

Libpcap not found when cross-compiling 32-bit on a 64-bit Debian

I am trying to compile a 32-bit application on 64-bit Debian Stretch. I have compiled several other applications successfully this way, but one app that uses the pcap library is giving me problems. There does not seem to be a 32-bit version of this library anywhere for my platform.
Problem description
When I try to link my application, like this:
g++ (...objectfiles-and-options...) -m32 -o myapp -lpthread -lpcap
I get the error
/usr/bin/ld: cannot find -lpcap
I checked, and there is indeed no libpcap.so (or variant thereof) in /usr/lib32. However, all other libraries I am using is present there (like libpthread). I tried to create soft-links to the 64-bit pcap-libraries in there, just in case they should be multi-platform compatible, but that only resulted in "skipping incompatible /usr/lib32/libpcap.so when searching for -lpcap".
I've installed libpcap-dev, libc6-dev-i386, gcc-multilib and g++-multilib (obviously, since cross-compilation works fine for all applications that does not use libpcap). I would suspect there should be a libpcap-dev-i386 I could install, but there does not seem to be one.
Perhaps I should mention that the application compiles and links successfully as 64 bit.
Does anyone know what I am missing here?
You can compile libpcap yourself. It's probably the better solution than depending on packages.
Use configure for 32bit architecture and than give your compiler LDFLAGS pointing to your lib or install it in /usr/lib32/

EDSDK 3.6 macOS - 32bit vs 64bit and linking errors

I'm trying to use the Canon EDSDK (latest version, v3.6 as of writing) in a simple, C++, command-line program on macOS (Sierra 10.12.6). I wish to utilize a simple Makefile environment and the usual apple compiler tools (llvm-clang) and avoid Xcode or any other heavy-weight IDE. The samples included with the SDK are all Xcode centric so I've had to roll my own here.
At present, I am able to compile a program to init the SDK and list connected cameras. As soon as I execute any EDSDK command however, I am getting a dynamic linking error:
Error loading /Library/Frameworks/EDSDK.framework/Versions/A/DppCore.bundle/Contents/PlugIns/DppCoreG.bundle/Contents/MacOS/DppCoreG: dlopen(/Library/Frameworks/EDSDK.framework/Versions/A/DppCore.bundle/Contents/PlugIns/DppCoreG.bundle/Contents/MacOS/DppCoreG, 262): no suitable image found
Did find: ... snip ... mach-o, but wrong architecture
The same error lists twice (both for DppCoreG). Upon examination, DppCoreG is compiled for 64bit architecture:
file /Library/Frameworks/..snip../DppCoreG
/Library/Frameworks/..snip../DppCoreG: Mach-O 64-bit bundle x86_64
However, there are other critical parts of the EDSDK that are compiled for 32bit architecture only:
file /...snip.../DPP.framework/DPP
/...snip.../DPP.framework/DPP: Mach-O dynamically linked shared library i386
How do I resolve this? The path of least resistance so far is to compile to i386 architecture explicitly (and the documentation explicitly states EDSDK is not 64-bit compatible). All is well except this one dynamic linking error (and in fact everything I've tried so far, which is just listing connected cameras, seems to work okay) but it is something I'm sure I can't continue to ignore or allow to persist in a production version of this project.
Here's a minimal example to cause the DYLD error:
#include <EDSDK.h>
#include <EDSDKTypes.h>
#include <EDSDKErrors.h>
int main(int argc, char** argv) {
EdsInitializeSDK();
EdsTerminateSDK();
return 0;
}
And probably more informative is the command to compile:
c++ -D __MACOS__ -g -arch i386 -I./deps/mac/include -framework DPP -framework EDSDK -o min min.cpp
I have the headers in the local include directory shown in the command and the frameworks installed under /Library/Frameworks.
Note that the c++ command is Apple LLVM version 8.1.0 (clang-802.0.42)
I've concluded that this is just an error on the part of those that deliver the EDSDK for mac. They should be compiling this particular bundle as a universal binary, not a 64bit binary. You can work around the problem by simply removing the offending bundle. It appears to just be a plugin and removing it does not seem to immediately affect the SDK. Assuming you have installed the EDSDK framework in /Library/Frameworks then just do this:
sudo rm -rf /Library/Frameworks/EDSDK.framework/Versions/Current/DppCore.bundle/Contents/PlugIns/DppCoreG.bundle
Enter your password when prompted (this assumes you are an admin account) and it will delete the offending plugin.
I have to believe that there may be consequences for removing this plugin at some point and if anyone knows more about this particular bundle/plugin and can explain what removing it will do I'd appreciate the additional insight.
In addition to #OllieBrown answer, I found in Xcode building for MacOS I had an additional item to remove to stop the link warnings.
link warning- EDSDK.framework/Versions/Current/DPPLibCom.bundle/Contents/MacOS/DPPLibCom: mach-o, but wrong architecture
removing EDSDK.framework/Versions/Current/DppLibCom.bundle stopped the warning.
Since the 3.x version there is a split between intergrated versions of DPP RAW capabilities. The original DPP works in x86 mode only and allows inspection and conversion of CR2 files on cams up until a certain models. See the API doc for the list. For recent camera models which rely on the new 64bit DPP engine (v4+?, dppcoreg) you would need x86_64 bit build so it dynamically links to use the latest features. Quite some (Raw) features are dropped, and gradually make their way back in in beta state.

Qt - How to deploy application dynamically on Linux?

I have an application that I built using Qt Creator on Linux and want to deploy it now. However, I don't want to statically build it as I don't want it to be open-sourced. I tried the ldd ./YourExecutable command, however that only lists (and not add) the additional dependencies the application needs in order for it to run. My question is, how do I gather the necessary dependencies without having to individually look for these files? Is there a tool, such as windeployqt.exe on Windows, that I can use on Linux for the same purpose? Or is there a better approach than the one I'm thinking of?
Get Cygwin setup.exe: http://www.cygwin.com/
1.1. Run setup.exe and continue to package selection list.
1.2. Under Devel catagory select tools you need for compiling your source. For
example 'GNU make'.
1.3. Finish installing.
Get linux crosscompilers for cygwin:
"cygwin-gcc-linux.tar.bz2" (68.2 Mb).
md5sum: 340e91a346f5bb17e660db10e43005b8
These compilers are made with crosstool 0.28-rc37. This package contains:
gcc-3.3.4 and gcc-2.95.3 for i386 (glibc 2.1.3) and gcc-3.3.3 for amd64
(glibc 2.3.2).
Note! There is now newer version of GCC avaible with glibc 2.3.2:
"cygwin-gcc-3.3.6-glibc-2.3.2-linux.tar.bz2 (i386, x86_64)".
2.1. Copy 'cygwin-gcc-linux.tar.bz2' to 'c:\cygwin' or install directory which
you selected in setup.exe.
2.2. Open Cygwin shell and change directory to root with 'cd /'.
2.3. Uncompress to Cygwin root with command:
'tar -jxvf cygwin-gcc-linux.tar.bz2'.
Cross-compilers are installed under '/opt/crosstool'. You can use theim
directly or with commands: gcc-linux, g++-linux, gcc-linux-2.95,
g++-linux-2.95, gcc-linux-x86_64 and g++-linux-x86_64.
From: Cross-compiling on Windows for Linux
More info here.
It sounds like you want to use the shared library deployment option:
http://doc.qt.io/qt-5/linux-deployment.html#creating-the-application-package
Then if you wanted to go further than that, you could look into making a .rpm or a .deb .
There are lots of examples of qt projects that are now available on GitHub and have packages made. Usually for prebuilt binaries you need to make one for x86 and a separate one for x64.
Hope that helps.

Installing C++ Libraries on OS X

I am trying to get my head around some basic concepts, but I can't seem to figure them out.
I am really confused over what it means to install (I think they are called libraries) for C++. I am trying to install OpenCV, but I don't know what needs to happen for it to be installed, how to check, or what really OpenCV is (Is it a library, framework, something else?).
My understanding is that OpenCV (and other libraries/frameworks) is distributed as only the source code so that is is able to work cross-platform. Then, after you download it, you have to build it (I don't know what build means though), and then link your compiler against it so that it can access the files? I don't know how any of this would be done, or really what this means. I think a lot of this is done by CMake, but I don't know what CMake really does, how you would use it, or how you would then utilize the library/framework in your code. Also, where would the libraries like OpenCV be installed, how would clang (or any other compiler/linker) know where to find them, and what kind of files would they be (.a, .dylib, .cpp, .hpp, executables, or a collection of everything)? Is this structure specific to C++ and OS X or is it more widespread?
I am not looking for a tutorial on how to install OpenCV or other libraries, but I am instead trying to learn how that actually works so I won't need tutorials in the future.
Before you can do any C/C++ development work on a Mac, you need to go to the App Store and download Xcode for free - it is Apple's IDE - Integrated Development Environment. Without Xcode, you will have no compiler (i.e. clang or gcc or g++) and no build tools, (i.e. make).
Install Xcode
If you are totally new to Mac, App Store looks like this:
and Xcode looks like this:
Install Command Line Tools
Next you must install Xcode's command-line tools, so start a Terminal - by pressing ⌘+SPACE and starting to type Terminal and when it guesses correctly, just hit Enter/Return. Copy and paste the following into Terminal and hit Enter/Return.
xcode-select --install
The above is called a "Spotlight Search" and is the easiest way to find anything on a Mac.
Install homebrew
Then, if you want to install OpenCV on a Mac, install a package manager such as homebrew which is a matter of copying and pasting a single line from the homebrew website into your Terminal. I will not show the line here in case it ever changes and someone looks at this in a few years, but it is easy to see if you go to the link above.
Find Packages
Then you can find any packages you want with:
brew search opencv # Look for packages called "opencv"
or
brew search boost # Look for "boost" libraries
Install OpenCV
So, for a vanilla (no special options) installation and build of OpenCV do this:
brew install opencv
Remove Packages
You can later remove any packages you no longer want with:
brew rm opencv
Update Packages
You can also update all installed packages with:
brew update && brew upgrade && brew cleanup
Build a Project
Once you have got it installed, you can start compiling and building your own project. It helps if you use the pkg-config package to pick up all the necessary compiler/linker settings you need, so I would suggest:
brew install pkg-config
Now you can compile and link with a really simple command like:
g++ $(pkg-config --cflags --libs opencv) process.cpp -o process
Then you can go on to use Xcode IDE later if you want to once you get started.
Build with Xcode
Once you have got started with basic compilation, you may want to start using Xcode to edit your programs, to do that, you must tell Xcode where the header files are and also where the libraries are and which libraries to link. This will vary with your OpenCV version, but you will need to alter the places marked in the two diagrams below. You will find these easily if you click them in order - green area first, then the yellow, then the blue, then the red.
The actual information that will need to go in the Xcode settings areas I have marked above can be found by running the same pkg-config command I suggested in the previous section. So run:
pkg-config --cflags opencv
to get the location of the header (include) files, and then run
pkg-config --libs opencv
to get the information you need to fill in for the linker in Xcode.

XCode 4 & OpenCV Libraries

I've been googling and trying for days to solve my problem I had n luck, so I'm asking my first question here.
I have a MacBook with Lion (1.7.4), Xcode 4.
I need to work on a C++ application made with Leopard and Xcode 3.
The application comes with its own OpenCV.framework and is made for 32-bit Architecture (as u can see in Fig. 1)
I've tried to get it working on Xcode 3, and it works just fine, no need to install OpenCV or stuff (that is because the OpenCV.framework is included in the project, right?).
On Xcode 4 it's not working. That's what I've tried:
Run it "as is": even thought the OpenCV.framework is in the application directory, i get the following error:
dyld: Library not loaded:
#executable_path/../Frameworks/OpenCV.framework/Versions/A/OpenCV
Referenced from:
/Users/fabrizioborgia/Library/Developer/Xcode/DerivedData/suiviGUI-awhilvjpoqatfdansnpqcexpnxaw/Build/Products/Debug/suiviGUI.app/Contents/MacOS/suiviGUI
Reason: image not found
Remove the OpenCV.framework, install OpenCV via MacPorts and link the libraries. Nope, the libraries are 64-bit, and my program is 32. Removed OpenCV AND MacPorts.
Remove the OpenCV.framework, install 32-bit OpenCV via Homebrew (brew install opencv --build32) and link the libraries. Nope, i get the following error, so I assume that the libraries are STILL 64-bit. Right? Removed OpenCV AND Homebrew.
ld: warning: ignoring file
/usr/local/Cellar/opencv/2.4.1/lib/libopencv_calib3d.2.4.1.dylib, file
was built for unsupported file format which is not the architecture
being linked (i386)
Remove the OpenCV.framework, install OpenCV 2.4.1 by myself (with make and stuff) and link the libraries in the project. Nope, if i run the program on 32-bit arch it tells me that the libraries are not for 32-bit arch.
In any case, if I try to run it on 64-bit the compilation is successful but the program doesn't work properly.
Guys, really, I'm out of ideas, maybe I'm on the wrong direction, maybe I just have to find another OpenCV.framework or there is some linking setting that I'm missing, and the program doesn't see the framwork.
Anyone can help?
Solved the problem.
I applied some sort fo "divide et impera approach" and I asked a new question here on SO, you can find it here: 32-bit OpenCV on OS X Lion? Possible? and I found out that MacPorts AND Homebrew AND the Cmake Approach install by default the native architecture (64-bit in my case) OpenCV libraries, I needed the 32-bit, so i followed those steps:
Step 1: Download OpenCV 2.4.0
Step 2: Download and install CMake.
Step 3: Untar the OpenCV package.
Step 4: Make a separate directory inside the OpenCV package for building
mkdir build
cd build
cmake -G "Unix Makefiles" -D CMAKE_OSX_ARCHITECTURES=i386 -D CMAKE_C_FLAGS=-m32 -D CMAKE_CXX_FLAGS=-m32 ..
(this will force the 32-bit compile)
make -j8
sudo make install
Step 5: Link the brand-new libraries in the Xcode project using the "Link Binary to Libraries" build phase.
Step 6: Hit "Run" :)
I would suggest that you get OpenCV working (if not already) in Lion with XCode 4 (tutorial). Test it with the example in the linked tutorial. Once that works, then copy over the classes you need from the project that you can't get working.
In other words, abandon the older project and rebuild it from a working project base.