I am trying to build one of the cgal demos from the developer website.
I have installed cgal using brew install cgal.
I also have installed qt5 version 5.15.2 using brew install qt5
However, when I try to build a demo (I am looking at the same one given in the example $HOME/CGAL-5.2.1/examples/Triangulation_) I get a long error from make that I don't know how to interpret.
My computer is running OS X 11.0.1.
Clang is version 12.0.0
/opt/homebrew/include/QtCore/qglobal.h:667:65: error: expected '>'
typename = std::enable_if_t<std::is_arithmetic_v<T> && std::is_arithmetic_v<U> &&
^
/opt/homebrew/include/QtCore/qglobal.h:667:65: error: expected ',' or '>' in template-parameter-list
/opt/homebrew/include/QtCore/qglobal.h:668:66: error: expected unqualified-id
std::is_floating_point_v<T> == std::is_floating_point_v<U> &&
^
/opt/homebrew/include/QtCore/qglobal.h:679:35: error: no type named 'Promoted' in namespace
'QTypeTraits::detail'
using Promoted = typename detail::Promoted<T, U>::type;
~~~~~~~~~~~~~~~~~^~~~~~~~
/opt/homebrew/include/QtCore/qglobal.h:679:43: error: expected ';' after alias declaration
using Promoted = typename detail::Promoted<T, U>::type;
^
/opt/homebrew/include/QtCore/qglobal.h:691:31: error: no template named 'Promoted' in namespace 'QTypeTraits'
constexpr inline QTypeTraits::Promoted<T, U> qMin(const T &a, const U &b)
~~~~~~~~~~~~~^
/opt/homebrew/include/QtCore/qglobal.h:693:28: error: no template named 'Promoted' in namespace 'QTypeTraits'
using P = QTypeTraits::Promoted<T, U>;
~~~~~~~~~~~~~^
/opt/homebrew/include/QtCore/qglobal.h:694:5: error: unknown type name 'P'
P _a = a;
^
/opt/homebrew/include/QtCore/qglobal.h:695:5: error: unknown type name 'P'
P _b = b;
^
/opt/homebrew/include/QtCore/qglobal.h:699:31: error: no template named 'Promoted' in namespace 'QTypeTraits'
constexpr inline QTypeTraits::Promoted<T, U> qMax(const T &a, const U &b)
~~~~~~~~~~~~~^
/opt/homebrew/include/QtCore/qglobal.h:701:28: error: no template named 'Promoted' in namespace 'QTypeTraits'
using P = QTypeTraits::Promoted<T, U>;
~~~~~~~~~~~~~^
/opt/homebrew/include/QtCore/qglobal.h:702:5: error: unknown type name 'P'
P _a = a;
^
/opt/homebrew/include/QtCore/qglobal.h:703:5: error: unknown type name 'P'
P _b = b;
^
/opt/homebrew/include/QtCore/qglobal.h:707:31: error: no template named 'Promoted' in namespace 'QTypeTraits'
constexpr inline QTypeTraits::Promoted<T, U> qBound(const T &min, const U &val, const T &max)
~~~~~~~~~~~~~^
/opt/homebrew/include/QtCore/qglobal.h:710:31: error: no template named 'Promoted' in namespace 'QTypeTraits'
constexpr inline QTypeTraits::Promoted<T, U> qBound(const T &min, const T &val, const U &max)
~~~~~~~~~~~~~^
/opt/homebrew/include/QtCore/qglobal.h:713:31: error: no template named 'Promoted' in namespace 'QTypeTraits'
constexpr inline QTypeTraits::Promoted<T, U> qBound(const U &min, const T &val, const T &max)
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
A very late answer but my solution was to uninstall Qt6 so that you only have Qt5. It is possible you may have both installed. Header files from both can conflict and confuse make. To properly do so:
Find all of the Qt versions you have installed with Homebrew:
brew list | grep qt
# You should see something like "qt qt#5"
Remove qt (which is Qt6)
brew uninstall qt
You should now have only Qt5 left. Try doing the build again, see if the issue is fixed.
Related
I am trying to setup my machine to be able to compile c++20 code. I have a simple example code
#include <concepts>
#include <iostream>
template<typename T>
requires std::integral<T>
auto gcd(T a, T b) {
if(b == 0) return a;
else return gcd(b, a%b);
}
int main() {
std::cout << "\n";
std::cout << gcd(100,10) << "\n";
}
which I am trying to compile on a MacOS (11.5.1/BigSur).
xcode version - Xcode 12.5.1
Build version 12E507
clang version - Apple clang version 12.0.5 (clang-1205.0.22.11)
compilation command
g++ -std=c++20 myfile.cpp
I get the following error:
myfile.cpp:25:24: error: 'T' does not refer to a value
requires std::integral<T>
^
myfile.cpp:24:19: note: declared here
template<typename T>
^
myfile.cpp:25:15: error: no member named 'integral' in namespace 'std'; did you mean 'internal'?
requires std::integral<T>
~~~~~^~~~~~~~
internal
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/ios:960:1: note: 'internal' declared here
internal(ios_base& __str)
^
myfile.cpp:26:1: error: expected expression
auto gcd(T a, T b) {
^
3 errors generated
Need help with this.
I'm currently reading Bjarne Stroustrup's "The C++ Programming Language" 4th Edition. In the first parts of the book, I found an usage of using looks like following:
// Error is in these 2 lines
template<typename T>
using Iterator<T> = typename T::iterator;
*see [**] for complete program and error message*
This is exactly what I found in the page 105. When I turned this into a complete program and tried to compile it, g++ gave me this error masseage:
> g++ -std=c++14 -o fnd find_all.cpp
find_all.cpp:13:15: error: expected '=' before '<' token
using Iterator<T> = typename T::iterator;
^
find_all.cpp:13:15: error: expected type-specifier before '<' token
I can't find any problem in this code, (I'm new to C++, I can't find the problem with my little knowledge)( More confusingly I found this on Bjarne's book )
Could someone tell me why does that code makes an error?
NOTE: However If I replaced Iterator<C> with typename C::iterator (see below), It works fine, there is no error!
[**]Complete Program and Error Message:
// Error is in these 2 lines
template<typename T>
using Iterator<T> = typename T::iterator;
// -------------------------------------------
// For the completeness I'll include my complete program here
template<typename C, typename V>
vector<Iterator<C>> find_all(C& c, V v) // find all occurrences of v in c
{
vector<Iterator<C>> res;
for (auto p = c.begin(); p!=c.end(); ++p)
if (∗p==v)
res.push_back(p);
return res;
}
void test()
{
string m {"Mary had a little lamb"};
for (auto p : find_all(m, 'a'))
if (*p == 'a')
cerr << "string bug!\n";
list<double> ld { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 1.1, 1.1 };
for (auto p : find_all(ld, 1.1))
if (*p == 1.1)
cerr << "list bug!\n";
vector<string> strv { "blue", "yellow", "red", "white", "orange", "blue" };
for (auto p : find_all(strv, "blue"))
if (*p == "blue")
cerr << "string vector bug!\n";
}
int main(void)
{
test();
return 0;
}
ERROR MESSAGE:
> g++ -std=c++14 -o fnd find_all.cpp
find_all.cpp:13:15: error: expected '=' before '<' token
using Iterator<T> = typename T::iterator;
^
find_all.cpp:13:15: error: expected type-specifier before '<' token
find_all.cpp:16:8: error: 'Iterator' was not declared in this scope
vector<Iterator<C>> find_all(C& c, V v)
^
find_all.cpp:16:17: error: template argument 1 is invalid
vector<Iterator<C>> find_all(C& c, V v)
^
find_all.cpp:16:17: error: template argument 2 is invalid
find_all.cpp:16:18: error: expected unqualified-id before '>' token
vector<Iterator<C>> find_all(C& c, V v)
^
find_all.cpp: In function 'void test()':
find_all.cpp:30:31: error: 'find_all' was not declared in this scope
for (auto p : find_all(m, 'a'))
^
find_all.cpp:35:32: error: 'find_all' was not declared in this scope
for (auto p : find_all(ld, 1.1))
^
find_all.cpp:40:37: error: 'find_all' was not declared in this scope
for (auto p : find_all(strv, "blue"))
First <T> must be omitted
template<typename T>
using Iterator = typename T::iterator;
When you define a class template or function template, you use:
template <typename T> struct Foo { };
template <typename T> T bar() { return T{}; }
You don't use Foo<T> or bar<T> when defining the templates.
Similarly, when using templates to define an alias, you need to use:
template <typename T>
using Iterator = typename T::iterator;
^^ Don't include <T>
I am trying to get a C++ code which used to compile fine in Visual Studio 2012
to compile under g++ in the cygwin environment.
template<typename M, typename V, typename E, typename F, typename H>
void _input_traits( M * pMesh )
{
if( M->m_input_traits |= VERTEX_UV )
{
_read_vertex_uv<M,V,E,F,H>( pMesh );
}
};
gcc produces the following errors
In file included from
MeshLib/algorithm/MapperMesh.h:27:0,
from main.cpp:10: MeshLib/core/Parser/traits_io.h: In function ‘void MeshLib::_input_traits(M*)’:
MeshLib/core/Parser/traits_io.h:367:7: error: expected
primary-expression before ‘->’ token if( M->m_input_traits |=
VERTEX_UV )
What primary expression is gcc talking about?
In M->m_input_traits |= VERTEX_UV shouldn't M be pMesh instead?\
M is the type while pMesh is the pointer that you want to use.
When I use boost 1.52.1 and gcc-4.7.1 to compile my code, the following errors appear. It seems this is conflict between boost and c++ library.
Could some know how to resolve this problem?
Many thanks for your reply.
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-
mingw32/4.7.1/../../../../include/boost/math/policies
/error_handling.hpp: In function 'bool boost::math::policies::
detail::check_overflow(std::complex<T>,
R*, const char*, const Policy&)':c:\program
files\mingw64\bin\../lib/gcc/x86_64-w64 mingw32/4.7.1
/../../../../include/boost/math/policies/error_handling.hpp:583:11:
error: expected unqualified-id before numeric constant
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-mingw32
/4.7.1/../../../../include/boost/math/policies/error_handling.hpp:
584:49: error: lvalue required as unary '&' operand
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/
../../../../include/boost/math/policies/
error_handling.hpp:584:107: error: 'im' was not declared in this
scope c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-mingw32
/4.7.1/../../../../include/boost/math/policies/error_handling.
hpp: In function 'bool boost::math::policies::detail::
check_underflow(std::complex<T>, R*, const char*, const Policy&)':
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64- mingw32
/4.7.1/../../../../include/boost/math/policies
/error_handling.hpp:602:11: error: expected unqualified-id before
numeric constant c:\program files\mingw64\bin\../lib/gcc/
x86_64-w64 mingw32/4.7.1/../../../../include/boost/math/policies
/error_handling.hpp:603:50: error: lvalue required as
unary '&' operand c:\program files\mingw64\bin\../lib/gcc/
x86_64-w64 mingw32/4.7.1/../../../../include/boost/math/policies
/error_handling .hpp:603:109: error: 'im' was not declared in
this scope c:\program files\mingw64\bin\../lib/gcc
/x86_64-w64-mingw32/4.7.1/../../../../include/boost/math/policies/
error_handling.hpp: In function 'bool boost::math::policies::
detail::check_denorm(std::complex<T>, R*, const char*,
const Policy&)':c:\program files\mingw64\bin\../lib/gcc
/x86_64-w64-mingw32/4.7.1/../../../../include/boost/
math/policies/error_handling.hpp:622:11: error: expected
unqualified-id before numeric constant
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-
mingw32/4.7.1/../../../../include/boost/math/policies/
error_handling.hpp:623:47: error: lvalue required as
unary '&' operand
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-
mingw32/4.7.1/../../../../include/boost/math/policies/
error_handling.hpp:623:103: error: 'im' was not declared
in this scope
The error appears in the code boost\math\policy\error_handling.hpp. But I am not sure when the program cite these functions. How does this error happen?
template <class R, class T, class Policy>
inline bool check_overflow(std::complex<T> val, R* result, const
char* function, const Policy& pol)
{
typedef typename R::value_type r_type;
r_type re, im;
bool r = check_overflow<r_type>(val.real(), &re, function, pol) || check_overflow<r_type>(val.imag(), &im, function, pol);
*result = R(re, im);
return r;
}
template <class R, class T, class Policy>
inline bool check_underflow(std::complex<T> val, R* result, const char* function, const Policy& pol)
{
typedef typename R::value_type r_type;
r_type re, im;
bool r = check_underflow<r_type>(val.real(), &re, function, pol) || check_underflow<r_type>(val.imag(), &im, function, pol);
*result = R(re, im);
return r;
}
Given this two functions and this noisy error message I can say that type that was used as parameter R doesn't defines value_type. Because of that, type r_type and variables im and re is not defined. As result you get error: 'im' was not declared in this scope error.
Using only provided code I can saw that type R has this requirements:
It must define type value_type
It must have constructor R(value_type real, value_type imagine)
All this means that you use some boost library that uses internaly check_underflow/check_overflow functions incorrectly, with incompatible template argument, I guess.
Scenario:
I'm building software across two different machines.
One of these machines has a fully compliant C++11 version of g++.
The other does not.
Machine 1 (Linux):
$ g++ --version
g++ (Ubuntu 5.1.0-0ubuntu11~14.04.1) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Machine 2 (Windows with Cygwin):
$ g++ --version
g++ (GCC) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
The C++ software I'm building across these two machines supports all the way back to C++98.
However, newer features of C++ will be used if they are available.
(The software in question, is C++ Catch for unit testing).
Problem:
I have a generic makefile that will build this software. On Cygwin it builds the software successfully. On Linux, with the newer compiler, it fails to build, because I assume it detects the version of the compiler and attempts to use more modern C++ features.
Here is a dump of the errors for glancing purposes. Mostly just nullptr_t related. Maybe something to do with newer rules on template deduction(not entirely sure):
catch.hpp:833:17: error: ‘nullptr_t’ in namespace ‘std’ does not name a type
inline std::nullptr_t opCast(std::nullptr_t) { return nullptr; }
^
catch.hpp:954:58: error: ‘template<Catch::Internal::Operator Op, class T> bool Catch::Internal::compare’ conflicts with a previous declaration
template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
^
catch.hpp:948:44: note: previous declaration ‘namespace Catch::Internal { }::compare’
template<Operator Op, typename T> bool compare( T* lhs, int rhs ) {
^
catch.hpp:954:53: error: ‘nullptr_t’ is not a member of ‘std’
template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
^
catch.hpp:954:70: error: expected primary-expression before ‘*’ token
template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
^
catch.hpp:954:72: error: ‘rhs’ was not declared in this scope
template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
^
catch.hpp:954:76: error: expression list treated as compound expression in initializer [-fpermissive]
template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
^
catch.hpp:954:44: warning: variable templates only available with -std=c++14 or -std=gnu++14
template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
^
catch.hpp:954:78: error: expected ‘;’ before ‘{’ token
template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
^
catch.hpp:957:66: error: ‘std::nullptr_t’ has not been declared
template<Operator Op, typename T> bool compare( T* lhs, std::nullptr_t ) {
^
catch.hpp:957:44: error: redefinition of ‘template<Catch::Internal::Operator Op, class T> bool Catch::Internal::compare(T*, int)’
template<Operator Op, typename T> bool compare( T* lhs, std::nullptr_t ) {
^
catch.hpp:948:44: note: ‘template<Catch::Internal::Operator Op, class T> bool Catch::Internal::compare(T*, int)’ previously declared here
template<Operator Op, typename T> bool compare( T* lhs, int rhs ) {
^
In file included from main.cpp:2:0:
catch.hpp:1088:38: error: ‘std::string Catch::toString’ redeclared as different kind of symbol
std::string toString( std::nullptr_t );
^
catch.hpp:1085:13: note: previous declaration ‘std::string Catch::toString(unsigned char)’
std::string toString( unsigned char value );
^
catch.hpp:1088:23: error: ‘nullptr_t’ is not a member of ‘std’
std::string toString( std::nullptr_t );
^
In file included from main.cpp:2:0:
catch.hpp:7336:38: error: ‘std::string Catch::toString’ redeclared as different kind of symbol
std::string toString( std::nullptr_t ) {
^
In file included from main.cpp:2:0:
catch.hpp:1232:13: note: previous declaration ‘template<class T, class Allocator> std::string Catch::toString(const std::vector<_Tp, _Alloc>&)’
std::string toString( std::vector<T,Allocator> const& v ) {
^
In file included from main.cpp:2:0:
catch.hpp:7336:23: error: ‘nullptr_t’ is not a member of ‘std’
std::string toString( std::nullptr_t ) {
This can be easily fixed on the Linux machine by ensuring that g++ gets compiled with the --std=c++11 flag. However, I don't want two separate makefiles across the two machines. I can't add the --std=c++11 flag to both builds, because version 4.9 doesn't have that flag yet.
Question:
How can I enable cross-compilation using the same command on different versions of g++? The code builds differently based on the versions of g++ -- in which case, sometimes the std flag needs to be passed.
Additional:
I've tried giving g++ the flag --std=c++98 for both builds, but it still fails on the Linux build. The goal here is to use the same kind of command across both machines.
On Windows platforms, I recommend to use Stephan Lavavej's Nuwen Distro. The only snag is that you can't use the std::thread facilities, but boost::thread provides an almost seamless alternative.
On Windows I would recommend switching to MSYS2 especially if you need c++11 support. Latest release has got mingw64 g++4.9.2. I was able to successfully built my Ubuntu project heavily using c++11/boost/python whereas I wasn't able to do that on Cygwin or MSVC2015 RC. MSYS2 has got it's package manager called pacman which is kind of apt-get/yum equivalent.
There is quite large number of prebuilt stuff which availibility you can check here.
Very compact introduction here