OpenCV build issue, can't find ext/atomicity.h - ios

I get the compiler error complaining about <ext/atomicity.h> when building a project incorporating OpenCV. Environment is Xcode 4.5 targeting iOS. It compiles fine for the simulator but fails when building for the device. Here's the error text:
/Users/Nick/projects/ios/opencv2.framework/Headers/core/operations.hpp:65:16: fatal error: 'ext/atomicity.h' file not found
#include <ext/atomicity.h>
I'm using the opencv2.framework, builusing cmake, using the instructions here.

By default XCode 4.5 generates new projects to build using the libc++ (LLVM C++ standard library with C++ 11 support). But OpenCV is expecting to be built against the GNU libstdc++ (GNU C++ standard library). <ext/atomicity.h> is apparently a GNU extension and isn't part of the LLVM libc++ standard library.
In your project's target settings, select libstdc++ (GNU C++ standard library) for the C++ Standard Library setting.
Very likely the atomicity.h requirement could be factored out of opencv or otherwise done in a LLVM libc++ compatible way. I didn't explore this but would be interested if anyone had insight on how this could be done.

I think it is the other way around. Looking at the output of the python script that builds opencv2.framework I get this:
-- C++ flags (Release): -stdlib=libc++ -headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden -fPIC -DNDEBUG -O3 [...]
which is most likely not what you want. So you need to compile the framework with libstdc++ or compile your app with the proper lib. From what I see I get problems when building my apps with libc++ but that might be me.

Related

clang/clang++ not detecting standard header files like iostream.h and stdio.h

I ran clang++ -v testfile.cpp and found that many standard headers were missing from the directory C:\LLVM\lib\clang\3.9.0\include. I downloaded a pre-built binary of clang 3.9.0 for 32 bit windows from this link.
Can someone please help me sort out this mess and explain me why the standard libraries are missing in the pre-build version of clang? I've searched the web for hours to get the answer and solution to this problem but couldn't find one. Thanks in advance.
why the standard libraries are missing in the pre-build version of clang?
Your Windows binary download comprises only binary build tools
plus a handful of clang-specific headers because you are supposed
to use clang, on Windows, in lieu of another native compiler that provides your
standard library. Similarly if you install clang on Linux you'll build against
the GCC standard library by default.
Your internet search seemingly failed to lead you to Installing clang++ to compile and link on Windows, which
explains how to integrate clang with the mingw-w64 GCC standard library for 32- and/or 64-bit work
in the manner that clang for Windows expects and supports.

Compiling C Source for iOS

I have some existing source code that is written in C that I want to build and include in my iOS project. The entire source package is very large and is built using existing Makefiles and GCC. It is producing static libraries (.a files) that I would love to move over to my iOS project. However, the static libraries the Makefile produces is for x86 processors, which obviously won't work on iOS.
Is there a way I can switch GCC to build for ARMv7/ARM64 instead, without making changes to the existing source (in most cases)? I know there is the -march switch for GCC or you can download ARM specific GCC compilers, so I know the general concept of building for a different architecture than the build machine.
To build for ARM on Mac OS, will I have to download a different GCC compiler or is that capability built into the default GCC?
I'm sorry for the lack of understanding of basic concepts here; I'm primarily a Java and Objective-C developer, so building source for different architectures is a mostly foreign concept to me.
Whilst GCC supports a good many CPU architecture and platforms, it is usually built for a single one. To compile for ARM you generally need an ARM-cross-compiling GCC targeted appropriately.
The default system compiler for MacOSX and iOS for all architectures is clang and has been for some time (the last version of GCC apple shipped in dev tools is creaking and obsolete, and definitely won't support ARMv8).
The usual way of getting clang is to install Xcode (free from the App Store). There's a option in the installer (and in the UI of Xcode) to install the command-line tool package. This installs sym-links in /usr/bin to the compiler, and installs a bunch of other stuff you might expect such as make.
clang is (mostly) command-line compatible with gcc, and furthermore, you'll find that if you run gcc from the command-line on a Mac with dev-tools installed, you in fact get clang.
$ gcc --version
Configured with: -- prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
clang comes with ARMv7, ARMv8, i686, x86_64 on MacOSX, and can be configured to compile for any of these from the command line (See documentation)
Given the above, there's a fair chance your code will compile with minimal changes to compiler-flags using the existing makefile. You might want to read the documentation for lipo - which allows you to produce multi-architecture binaries.

Why does mingw-w64 gfortran fail to statically link libraries when the -static flag is passed?

Disclaimer: I'm fairly deep into my particular compiling issue but quite new to the world of compiling.
Background:
I'm working on a Windows 7, 64 bit machine. I'm attempting to compile a rather large fortran program using mingw-w64. The compile process is controlled by SCONS (similar or derived from gnu Make). I have successfully compiled this program via scons using g95 and mingw gfortran. I have attempted use tdm-gcc and 'ruben' builds of mingw-w64 with identical, unsatisfactory results. I am passing the -static argument to the compiler (gfortran.exe). I have tried using both the gfortran and x86_64-w64-mingw32-gfortran compile commands with identical results.
Problem:
When attempting to compile a 64bit version of my program, despite passing the -static argument to the gfortran compiler, when I attempt to run the built executable, it errors out claiming that it can't find various dll's (libgfortran, libgcc, libquadmath, generically speaking). If I copy those libraries to the working directory, the built program runs without error and performs as expected.
Anecdotal Summary:
mingw-w64 gfortran appears to be ignoring the -static compile flag
If there is any additional information I can provide to help in solving this, please let me know.
Thanks,
JTJ

Error compiling NEON for iOS 5.1 with clang integrated assembler

I try to compile NEON assembly code with LLVM clang integrated macro assembler (the LLVM compiler shipped with XCode 4.3) and get the following error:
vld1.8 {D0}, [R0] - invalid operand for instruction
What can be the reason? Why this instruction is successfuly compiled by GAS for Android and can't be compiled by 'clang -integrated-as ...' for iOS? Thanks.
After a day of experimenting I've found a solution. I've just compiled LLVM from the SVN source base (version 3.2). The integrated macro assembler in LLVM 3.2svn supports ARM NEON ISA much better compared to LLVM 3.0svn shipped with XCode 4.3.1. The problem with VLD NEON instruction have been automatically resolved.
Those, who use gas-preprocessor.pl Perl script, may try to switch from GAS 1.38 (it's external GNU assembler used by LLVM on Mac OS X 10.7.X) to LLVM integrated macro assembler and stop using unnecessary preprocessing.
I've not used clang for assembly but the following site might help: ARM Assembly
In addition, this may help as it solved someone else's issue with ARM assembly (selecting the correct device, lower case instructions etc...): Useful Stackoverflow answer

Cross Compiling a library from intel to arm

I am using open source C++ library DCMTK from http://dicom.offis.de/dcmtk.php.en.
I have successfully compiled this library on Windows using VC++ IDE, MacOS Xcode, Mac iOS simulator.
But I am not able to compile this library on iOS device as it is ARM based architecture.
DCMTK library compiled very well on Intel architecture.
Now my problem statement is :-
I need to compile this DCMTK C++ library on ARM architecture by cross compilation.
I am using Ubuntu 64 bit machine for cross compilation.
I have installed binaries from GNU ARM tool chain from http://www.gnuarm.com/
I am using GCC toolchain 4.0 binutils-2.16.1, gcc-4.0.2-c-c++, newlib-1.14.0, insight-6.4, TAR BZ2 [65.5MB] binaries for Ubuntu 64 bit machine for ARM cross compilation.
After Installing these binaries on Ubuntu I have set PATH environment variable to
PATH=$PATH/gnu_arm/bin
For configuring the DCMTK C++ library I have run the following command on shell
CC=arm-elf-gcc CXX=arm-elf-g++ AR=arm-elf-ar RANLIB=arm-elf-ranlib ARFLAGS=cruv ./configure –prefix=$home_dicom –target=arm-elf –host=arm-elf –enable-std-includes –disable-threads
It creates a make file properly. Now I am trying to compile the code by using make command, but facing so many compilation errors like :-
1) I tried to compile my first dependent C++ library that is ofstd.
I got error for DIR*, struct dirent, opendir(), closedir() calls.
It includes for these calls, but I did not found any definitions for the above calls in this header file.
2) When I compile another library oflog I got the following errors like
error: nthos was not declared in this scope
error: ntohl was not declared in this scope
error: htons was not declared in this scope
error: htonl was not declared in this scope.
These calls are networking calls and are not defined in any of the header file from GNU ARM tool.
I tried to download the sources of ARM binaries and extracted the tar files and try to copy missing header files to installed GNU ARM on Ubuntu.
For some files it compiles after doing changes to copied header files, and for some again it gives compilation errors.. There is a loop of compilation errors for every file present under DCMTK library as some of the standard header files are missing.
Please suggest if there is any other tool chain available for ARM cross compilation on Ubuntu 64 bit machine.
Or any other good solution apart from this.
Thanks!!!
Amit
There are many areas for problems when it comes to cross compiling. There are three main flags for cross compiling. -host , -target, and -build. The -host flash is the machine in which the resulting binaries will run on. The -build flash is the system in which you will be compiling on. The -target flag is for building libraries that will be used in cross compiling. So if you were to build your own gcc tool chain. So in your case you won't set the target flag as we're not building a tool chain. the -host flag will be arm-elf. And the -build flag will be amd64.
Usually a cross compilation fails if there are inconsistencies between the regular c compiler and the cross compiler. I have compiled several libraries for the avr32 with a toolchain generated by buildroot, but in some cases (socat project for example) it hasn't been possible.
Your host, your target and the CXX flags look ok. I think it is not necessary to put the AR flag (that is the idea with the host and target option).
In other hand, this is an example for the expat libraries for the avr32:
./configure --host=avr32-linux --prefix=/home/juan/builds/build_expat/ CC=avr32-linux-gcc
make; make install
I can recommend you that tries to cross compile from an ia32 architecture. I had several problems with that ubuntu in the past.

Resources