Errors while migrating Qt project from Linux to Windows - windows

I have a Qt project develop on linux, but now I need to compile on windows. I'm having a couple of problems in the migration process.
The first error I'm getting it's:
C:\Qt\Qt5.5.1\Tools\mingw492_32\i686-w64-mingw32\include\c++\bits\c++0x_warning.h:32: error:
#error This file requires compiler and library support for the ISO C++ 2011 standard.
This support is currently experimental, and must be enabled with the
-std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support for the \
^
and this it's how I'm putting it in the .pro of my project
QMAKE_CXXFLAGS += -std=c++11
I also try with
CONFIG += c++11
but the problem continuous.
To give a little more of information, I'm using the MinGW compiler that the Qt Creator install and the extension of my Headers and Sources are: .H and .C (Just in case this have anything to do with the problem, because I've seen that Qt always uses .cpp)
What could be the cause of the problem ?? If something it's unclear or more information it's needed please let me know.

I solve the problem, for me it worked when I change the extension of my sources, I change .C for .cc

Related

macOS Sierra CoreFoundation error while compiling wxWidgets for SimSpark

I am trying to to compile wxWidgets 3.0.2 found here.
I need this library, so that I can compile SimSpark.
I have tried installing the library via MacPorts - this does work. But when I try to compile SimSpark, the compiler states the following:
In file included from /opt/local/include/gcc49/c++/type_traits:35:0,
from /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/include/wx-3.0/wx/strvararg.h:25,
from /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/include/wx-3.0/wx/string.h:46,
from /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/include/wx-3.0/wx/memory.h:15,
from /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/include/wx-3.0/wx/object.h:19,
from /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/include/wx-3.0/wx/event.h:16,
from /Users/YEED/Downloads/simspark-0.2.4/plugin/inputwx/inputwx.cpp:23:
/opt/local/include/gcc49/c++/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
I believe that I need to compile wxWidgets with C++11 support, since I already included the C++11 relevant flags when making SimSpark.
When I try to compile wxWidgets, I get a bunch of compiler errors that refer to the same .h file - which is part of CoreFoundation:
In file included from /usr/include/Availability.h:184:0,
from /usr/include/stdlib.h:61,
from /usr/include/assert.h:44,
from ../include/wx/debug.h:13,
from ../include/wx/defs.h:743,
from ../include/wx/wxprec.h:12,
from ../src/common/filefn.cpp:20:
/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDateFormatter.h:53:34: error: expected '}' before '__attribute__'
kCFISO8601DateFormatWithYear API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) = (1UL << 0),
When you look into that specific file, there are a bunch of lines that miss a closing ) and resemble the one printed by the compiler as well. (There should be a closing ) before the comma at the end of the line, right?)
So my question is, is this an actual error in CoreFoundation? If so, how can I fix this or work around it? Or am I actually completely misunderstanding the compiler error thrown when compiling SimSpark in the first place?
EDIT:
I couldn't get wxWidgets to compile, but I have fixed my issues compiling SimSpark with the MacPorts version of wxWidgets. The problem lay within using different compilers (gcc and clang) for the two.

Let cmake with clang use c++11 (c++14)

My cmake project shall compile c++14 code. It also uses the CMakeLists.txts included from its external libraries (which are git submodules in my project). The build fails on macOS Sierra (cmake 3.6.2) because the default STL of clang is old and doesn't handle c++11. As far as I understand, there are two STLs shipped with clang: libstdc++ (from gcc) (default) or libc++. So if I add the -stdlib=libc++ option to cmake, the source compiles:
add_compile_options( "$<$<COMPILE_LANGUAGE:CXX>:-std=c++14>" )
add_compile_options( "$<$<COMPILE_LANGUAGE:CXX>:-stdlib=libc++>" )
But then it fails at link time because it tries to use libstdc++ for linking. How do I specify in cmake that the new STL libc++ shall be used for the whole build process?
PS: What is the rationale behind clang using the gcc STL by default if it is too old? Could I permanently specify which STL it shall use? Or am I doing something completely wrong (could some of my subprojects silently force gcc?)?
You should rely on CMake to handle compile options. Just specify the wanted standard version:
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
target_compile_features can also be used to require particular features of the standard (and implicitly ask CMake to set the adequate configuration). More information here.
EDIT
You figured out the solution, you also had to remove the following line in the CMakeLists of Ogred3D:
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.7)
Removing it prevented CMake to add the flag mmacosx-version-min=10.7 causing the error.
I suppose, you also need to pass that flang to the linker in the clang case:
link_libraries("-stdlib=libc++")

changing compiler library standards on ubuntu

I am compiling one code repository which has a makefile,
make INSTALL_PREFIX=/usr/local install
and I get the following error:
This file requires compiler and library support for the ISO C++ 2011
standard. This support must be enabled with the -std=c++11 or
-std=gnu++11 compiler options.
How can I enable ISO C++ 2011 standard?
Thanks,
You don't give any details on the code repository, does it use just a standard makefile, autotools, cmake ?
You may be able to just do a export CPPFLAGS="-std=c++11" prior to building building the code.

Compiling Clang on Windows

I followed instructions at http://clang.llvm.org/get_started.html
I compiled latest trunk of llvm and clang with MSVC 2010. Now I can compile simple programs with Clang but when I tried to compile this program I got a lot of errors.
Here is program:
#include <algorithm>
int main(){ return 0; }
And here are some of errors:
In file included from hello.cpp:1:
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include\algorithm:6:
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include\memory:987:
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include\intrin.h:24:
In file included from H:/LLVM/build/bin/Debug/../lib/clang/3.3/include\immintrin.h:32:
In file included from H:/LLVM/build/bin/Debug/../lib/clang/3.3/include\xmmintrin.h:988:
H:/LLVM/build/bin/Debug/../lib/clang/3.3/include\emmintrin.h:1384:22: error: expected expression
return (__m128)__in;
^
H:/LLVM/build/bin/Debug/../lib/clang/3.3/include\emmintrin.h:1390:23: error: expected expression
return (__m128i)__in;
^
H:/LLVM/build/bin/Debug/../lib/clang/3.3/include\emmintrin.h:1396:23: error: expected expression
return (__m128d)__in;
^
Complete output from Clang: http://pastebin.com/qi87K8qr
Clang tries to use MSVC headers but it doesn't work. Maybe I should use libc++ or libstdc++ instead, but how to do that?
Note I'm not interested in precompiled clang binaries
Yes, clang simply does not support all of Microsoft's extended C++ syntax, and therefore cannot parse Microsoft's C++ headers which use that syntax. Not only that but Clang also doesn't have complete support for Microsoft's C++ ABI, name mangling, etc. I believe Clang on Windows works alright with C, however.
To use a different C++ standard library instead you can make clang ignore the normal header and library directories with, IIRC, -nostdinc++ and -nostdlib++. Then you can tell clang the include and library directories you want to use (using -isystem or -I or whatever). However I'm not sure whether libc++ or libstdc++ work under those circumstances, since they probably depend on things that the Windows C runtime library does not have.
Chandler Carruth mentioned at Going Native 2013 that there are now alpha builds of clang for Windows with Visual Studio integration. Lots of stuff is broken, for example, streams (so good old hello world won't work). However, there is a lot of effort being put into making clang work on Windows, so expect it to get pretty good pretty fast.
Errors were in the header supplied with clang itself. Looks like it can't handle MMX/SSE types properly. Try to add -msse -msse2 switches to the command line.
I'm using libstdc++ and built clang using VS2012Express for desktop. The cmake string was "Visual Studio 11 Win64" and the essential dirs. are specified using -I argument.
My guess you program could work if I used mingw headers for Windows.

linking libraries in qt creator for c++ project

I am creating normal c++ project using QT creator .
I need to link the boost library. I have used this in eclipse project under Project Properties/C C++ build/Gcc C++ linker/-l boost_filesystem but i am not sure how to do it in QT creator.
I use Qt, but not Qt-Creator so I'm not sure where in it's UI you might do this.
But in the .pro file (the input to the makefile), you would specify the library with:
LIBS += -lboost_filesystem # assuming 'boost_filesystem' is the name of the lib file
LIBS += -L/[wherever boost lib files are on your system]
"-l" is the file name and "-L" is the library path name.
LIBS += -lboost_filesystem -L/[wherever boost lib files are on your system]
works too.
"+=" appends it to the current QMake variables, be careful about using "=", unless you really intend to replace the values.
I don't know, if this is still an issue for you, but I answer because it may help some others like me who had a similar issue.
As far as I understood it: When you use QtCreator with normal C++ you will be asked which build tool to use. I have chosen CMake, so from now on everything goes via CMake and less things go directly via QtCreator. That's the reason that there is no .pro file anymore.
So what I did to resolve the issue was to add following line after the add_executable(...) line in the CMakeLists.txt file:
target_link_libraries(my_project_name -lboost_system)
Note: I just needed lboost_system, but I think that just expanding the list with -lboost_filesystem etc.. will do the job.
Hope that it helps somebody.

Resources