Configure Eclipse CDT or Codeblocks to get LLVM IR intellisense - c++

I want to configure Eclipse (or Codeblocks) so that when I write a pass, I can at least take advantage of Intellisense (even if building passes directly from within Eclipse is not possible). Update: I am getting at least some intellisense once I enabled Parsing-based Proposals in Eclipse (details below)
So far I have configured Eclipse to use clang to compile simple C++ programs.
To get intellisense for LLVM pass, I added /usr/local/include to Includes directories and tried code:
#include <iostream>
#include <llvm/IR/Function.h>
using namespace std:
int main() {
cout << "Hello World" << endl;
return 0;
}
It doesn't fail on #include <llvm/IR/Function.h> itself (i.e. it can find this header file), but upon including subsequent files, gives me
/usr/local/include/llvm/Support/DataTypes.h:58:3: error: "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
Any pointers to how I could make it give me intellisense at least?
Complete Log
01:22:48 **** Rebuild of configuration Debug for project HelloWorld2 ****
Info: Internal Builder is used for build
clang++ -I/usr/local/include -O0 -emit-llvm -g3 -Wall -c -fmessage-length=0 -o src/HelloWorld2.bc ../src/HelloWorld2.cpp
In file included from ../src/HelloWorld2.cpp:10:
In file included from /usr/local/include/llvm/IR/Function.h:22:
In file included from /usr/local/include/llvm/IR/Argument.h:17:
In file included from /usr/local/include/llvm/ADT/Twine.h:14:
/usr/local/include/llvm/Support/DataTypes.h:58:3: error: "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
# error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
^
/usr/local/include/llvm/Support/DataTypes.h:62:3: error: "Must #define __STDC_CONSTANT_MACROS before " "#including Support/DataTypes.h"
# error "Must #define __STDC_CONSTANT_MACROS before " \
^
In file included from ../src/HelloWorld2.cpp:10:
In file included from /usr/local/include/llvm/IR/Function.h:22:
In file included from /usr/local/include/llvm/IR/Argument.h:19:
In file included from /usr/local/include/llvm/IR/Attributes.h:19:
In file included from /usr/local/include/llvm/ADT/ArrayRef.h:14:
In file included from /usr/local/include/llvm/ADT/SmallVector.h:20:
/usr/local/include/llvm/Support/MathExtras.h:273:24: error: use of undeclared identifier 'INT64_C'
return N >= 64 || (-(INT64_C(1)<<(N-1)) <= x && x < (INT64_C(1)<<(N-1)));
^
/usr/local/include/llvm/Support/MathExtras.h:273:56: error: use of undeclared identifier 'INT64_C'
return N >= 64 || (-(INT64_C(1)<<(N-1)) <= x && x < (INT64_C(1)<<(N-1)));
^
/usr/local/include/llvm/Support/MathExtras.h:299:26: error: use of undeclared identifier 'UINT64_C'
return N >= 64 || x < (UINT64_C(1)<<(N));
^
/usr/local/include/llvm/Support/MathExtras.h:331:24: error: use of undeclared identifier 'INT64_C'
return N >= 64 || (-(INT64_C(1)<<(N-1)) <= x && x < (INT64_C(1)<<(N-1)));
^
/usr/local/include/llvm/Support/MathExtras.h:331:56: error: use of undeclared identifier 'INT64_C'
return N >= 64 || (-(INT64_C(1)<<(N-1)) <= x && x < (INT64_C(1)<<(N-1)));
^
In file included from ../src/HelloWorld2.cpp:10:
In file included from /usr/local/include/llvm/IR/Function.h:22:
In file included from /usr/local/include/llvm/IR/Argument.h:19:
In file included from /usr/local/include/llvm/IR/Attributes.h:19:
In file included from /usr/local/include/llvm/ADT/ArrayRef.h:14:
/usr/local/include/llvm/ADT/SmallVector.h:232:20: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
void push_back(T &&Elt) {
^
/usr/local/include/llvm/ADT/SmallVector.h:476:33: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
iterator insert(iterator I, T &&Elt) {
^
/usr/local/include/llvm/ADT/SmallVector.h:645:46: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
SmallVectorImpl &operator=(SmallVectorImpl &&RHS);
^
/usr/local/include/llvm/ADT/SmallVector.h:383:12: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for (auto I = this->end(), E = this->begin() + N; I != E; ++I)
^
/usr/local/include/llvm/ADT/SmallVector.h:764:70: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
SmallVectorImpl<T> &SmallVectorImpl<T>::operator=(SmallVectorImpl<T> &&RHS) {
^
/usr/local/include/llvm/ADT/SmallVector.h:878:27: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
SmallVector(SmallVector &&RHS) : SmallVectorImpl<T>(N) {
^
/usr/local/include/llvm/ADT/SmallVector.h:883:44: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
const SmallVector &operator=(SmallVector &&RHS) {
^
In file included from ../src/HelloWorld2.cpp:10:
In file included from /usr/local/include/llvm/IR/Function.h:22:
In file included from /usr/local/include/llvm/IR/Argument.h:19:
In file included from /usr/local/include/llvm/IR/Attributes.h:20:
In file included from /usr/local/include/llvm/ADT/FoldingSet.h:21:
/usr/local/include/llvm/Support/Allocator.h:134:70: error: expected expression
BumpPtrAllocatorImpl<AllocatorT, SlabSize, SizeThreshold>> {
^
/usr/local/include/llvm/Support/Allocator.h:346:2: error: expected a type
};
^
/usr/local/include/llvm/Support/Allocator.h:346:2: error: expected class name
/usr/local/include/llvm/Support/Allocator.h:346:2: error: expected '{' after base class list
/usr/local/include/llvm/Support/Allocator.h:362:53: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
SpecificBumpPtrAllocator(SpecificBumpPtrAllocator &&Old)
^
/usr/local/include/llvm/Support/Allocator.h:366:64: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
SpecificBumpPtrAllocator &operator=(SpecificBumpPtrAllocator &&RHS) {
^
/usr/local/include/llvm/Support/Allocator.h:375:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto DestroyElements = [](char *Begin, char *End) {
^
/usr/local/include/llvm/Support/Allocator.h:375:28: error: expected expression
auto DestroyElements = [](char *Begin, char *End) {
^
/usr/local/include/llvm/Support/Allocator.h:381:10: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for (auto I = Allocator.Slabs.begin(), E = Allocator.Slabs.end(); I != E;
^
/usr/local/include/llvm/Support/Allocator.h:381:29: error: no member named 'Slabs' in 'llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096, 4096>'
for (auto I = Allocator.Slabs.begin(), E = Allocator.Slabs.end(); I != E;
~~~~~~~~~ ^
/usr/local/include/llvm/Support/Allocator.h:381:58: error: no member named 'Slabs' in 'llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096, 4096>'
for (auto I = Allocator.Slabs.begin(), E = Allocator.Slabs.end(); I != E;
~~~~~~~~~ ^
/usr/local/include/llvm/Support/Allocator.h:383:52: error: no member named 'computeSlabSize' in 'llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096, 4096>'
size_t AllocatedSlabSize = BumpPtrAllocator::computeSlabSize(
~~~~~~~~~~~~~~~~~~^
/usr/local/include/llvm/Support/Allocator.h:384:35: error: no member named 'Slabs' in 'llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096, 4096>'
std::distance(Allocator.Slabs.begin(), I));
~~~~~~~~~ ^
/usr/local/include/llvm/Support/Allocator.h:386:35: error: no member named 'Slabs' in 'llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096, 4096>'
char *End = *I == Allocator.Slabs.back() ? Allocator.CurPtr
~~~~~~~~~ ^
/usr/local/include/llvm/Support/Allocator.h:386:60: error: no member named 'CurPtr' in 'llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096, 4096>'
char *End = *I == Allocator.Slabs.back() ? Allocator.CurPtr
~~~~~~~~~ ^
/usr/local/include/llvm/Support/Allocator.h:392:10: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for (auto &PtrAndSize : Allocator.CustomSizedSlabs) {
^
/usr/local/include/llvm/Support/Allocator.h:392:39: error: no member named 'CustomSizedSlabs' in 'llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096, 4096>'
for (auto &PtrAndSize : Allocator.CustomSizedSlabs) {
~~~~~~~~~ ^
/usr/local/include/llvm/Support/Allocator.h:392:27: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
for (auto &PtrAndSize : Allocator.CustomSizedSlabs) {
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
13 warnings and 20 errors generated.
01:22:50 Build Finished (took 1s.509ms)
UPDATE: Eclipse does give me intellisense (at least some of it), I had to check Parsing-based Proposals in Window -> Preferences -> C/C++ -> Editor -> Content Assist -> Advanced (It was unchecked by default).

This is not answering the question directly, but it will ensure, you have a correctly working build environment. It is specific for code blocks.
First checkout the source tree of llvm (directly taken from the getting started guide):
git clone http://llvm.org/git/llvm.git
cd llvm/tools
git clone http://llvm.org/git/clang.git
cd ..
cd projects
git clone http://llvm.org/git/compiler-rt.git
git clone http://llvm.org/git/libcxx.git
git clone http://llvm.org/git/libcxxabi.git
git clone http://llvm.org/git/test-suite.git
git clone http://llvm.org/git/openmp.git
Remove anything you don't like.
Then create an directory outside the llvm directory:
cd ..
mkdir build
Change your directory (cd) to there and run:
cd build
cmake -g "CodeBlocks - Unix Makefiles" <your configure options> ../llvm
Assuming llvm shares the root path, otherwise change the ../llvm line to the correct path. Then open it as an existing project in code::blocks.
If all went well, your build environment is setup correctly and code completion should work.

Related

Using unordered_map on my g++ (5.1.0) compiler in command prompt shows error

I have recently downloaded MinGW into my computer but on using certain containers and iterators like unordered_map and auto it shows an unexpected error.
my code is as follows :
#include <bits/stdc++.h>
#include<unordered_map>
using namespace std;
int main()
{
unordered_map<string, int> umap;
umap["GeeksforGeeks"] = 10;
umap["Practice"] = 20;
umap["Contribute"] = 30;
for (auto x : umap)
cout << x.first << " " << x.second << endl;
return 0;
}
it gives the following error :
C:\Users\naima\Documents\cpp>g++ -o try2 try2.cpp
In file included from C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/unordered_map:35:0,
from try2.cpp:2:
C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/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.
#error This file requires compiler and library support for the \
^
try2.cpp: In function 'int main()':
try2.cpp:9:5: error: 'unordered_map' was not declared in this scope
unordered_map<string, int> umap;
^
try2.cpp:9:25: error: expected primary-expression before ',' token
unordered_map<string, int> umap;
^
try2.cpp:9:27: error: expected primary-expression before 'int'
unordered_map<string, int> umap;
^
try2.cpp:11:5: error: 'umap' was not declared in this scope
umap["GeeksforGeeks"] = 10;
^
try2.cpp:15:15: error: 'x' does not name a type
for (auto x : umap)
^
try2.cpp:19:5: error: expected ';' before 'return'
return 0;
^
try2.cpp:19:5: error: expected primary-expression before 'return'
try2.cpp:19:5: error: expected ';' before 'return'
try2.cpp:19:5: error: expected primary-expression before 'return'
try2.cpp:19:5: error: expected ')' before 'return'
The compiler told you exactly what was wrong. It usually will.
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.
You just have to compile with the proper flag, -std=c++11. I don't know if you are version-matching against what graders use or what, but there are very few good reasons to be on a minGW compiler where support for an 8 year old standard is still considered experimental.
You can see that it works as expected here: https://godbolt.org/z/JQxL00
If you remove the -std=c++11 flag, it will fail to compile and give you the same error message.
You might also notice that I altered the includes to only include what I use. This results in a much faster compile time, smaller executable, and an easier to understand piece of code (Since it is plain to see what standard features are being used). You also avoid polluting your namespace.

cmake + qt + vtk: Compilation errors in macOS Mojave

I'm running macOS Mojave (10.14.3).
After the upgrade to Mojave something in my system changed and I no longer can compile code having VTK and Qt.
A (not) working example can be found in the examples given by VTK.
It's worth to mention, that I can compile the other examples not involving qt.
I use homebrew to install everything I need.
Hier are the logs:
cmake ..
-- The C compiler identification is AppleClang 10.0.1.10010046
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- VTK_VERSION: 8.1.2
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/chraibi/Downloads/VTK_Examples/SideBySideRenderWindowsQt/build
and
make
In file included from /Users/user/Downloads/VTK_Examples/SideBySideRenderWindowsQt/build/SideBySideRenderWindowsQt_autogen/mocs_compilation.cpp:2:
In file included from /Users/user/Downloads/VTK_Examples/SideBySideRenderWindowsQt/build/SideBySideRenderWindowsQt_autogen/EWIEGA46WW/moc_SideBySideRenderWindowsQt.cpp:9:
In file included from /Users/user/Downloads/VTK_Examples/SideBySideRenderWindowsQt/build/SideBySideRenderWindowsQt_autogen/EWIEGA46WW/../../../SideBySideRenderWindowsQt.h:6:
In file included from /usr/local/opt/qt/lib/QtWidgets.framework/Headers/QMainWindow:1:
In file included from /usr/local/opt/qt/lib/QtWidgets.framework/Headers/qmainwindow.h:44:
In file included from /usr/local/opt/qt/lib/QtWidgets.framework/Headers/qwidget.h:52:
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:51:82: error: invalid token at start of a preprocessor expression
#if !defined(Q_CC_GNU) || defined(Q_CC_INTEL) || defined(Q_CC_CLANG) || Q_CC_GNU >= 408
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:68:1: error: unknown type name 'Q_DECL_CONST_FUNCTION'
Q_DECL_CONST_FUNCTION inline uint qHash(QSizePolicy key, uint seed = 0) Q_DECL_NOTHROW;
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:68:23: error: expected unqualified-id
Q_DECL_CONST_FUNCTION inline uint qHash(QSizePolicy key, uint seed = 0) Q_DECL_NOTHROW;
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:91:5: error: unknown type name 'Q_ENUM'
Q_ENUM(Policy)
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:91:19: error: expected ';' at end of declaration list
Q_ENUM(Policy)
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:110:35: error: use of undeclared identifier 'ControlType'
Q_DECLARE_FLAGS(ControlTypes, ControlType)
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:111:5: error: unknown type name 'Q_FLAG'
Q_FLAG(ControlTypes)
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:111:12: error: duplicate member 'ControlTypes'
Q_FLAG(ControlTypes)
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:110:21: note: previous declaration is here
Q_DECLARE_FLAGS(ControlTypes, ControlType)
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:111:25: error: expected ';' at end of declaration list
Q_FLAG(ControlTypes)
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:132:5: error: unknown type name 'Q_DECL_RELAXED_CONSTEXPR'
Q_DECL_RELAXED_CONSTEXPR void setHorizontalPolicy(Policy d) Q_DECL_NOTHROW { bits.horPolicy = d; }
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:132:30: error: expected member name or ';' after declaration specifiers
Q_DECL_RELAXED_CONSTEXPR void setHorizontalPolicy(Policy d) Q_DECL_NOTHROW { bits.horPolicy = d; }
~~~~~~~~~~~~~~~~~~~~~~~~ ^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:136:73: error: expected ';' at end of declaration list
QT_SIZEPOLICY_CONSTEXPR Qt::Orientations expandingDirections() const Q_DECL_NOTHROW {
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:153:58: error: expected ';' at end of declaration list
QT_SIZEPOLICY_CONSTEXPR int horizontalStretch() const Q_DECL_NOTHROW { return static_cast<int>(bits.horStretch); }
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:176:47: error: expected ';' at end of declaration list
QT_SIZEPOLICY_CONSTEXPR QSizePolicy(int i) Q_DECL_NOTHROW : data(i) { }
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:178:50: error: unknown type name 'Bits'
QT_SIZEPOLICY_CONSTEXPR explicit QSizePolicy(Bits b) Q_DECL_NOTHROW : bits(b) { }
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:178:57: error: expected ';' at end of declaration list
QT_SIZEPOLICY_CONSTEXPR explicit QSizePolicy(Bits b) Q_DECL_NOTHROW : bits(b) { }
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:223:9: error: unknown type name 'Bits'
Bits bits;
^
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:231:33: error: use of undeclared identifier 'Q_RELOCATABLE_TYPE'; did you mean 'Q_MOVABLE_TYPE'?
Q_DECLARE_TYPEINFO(QSizePolicy, Q_RELOCATABLE_TYPE);
^
/usr/local/include/QtCore/qglobal.h:2272:5: note: 'Q_MOVABLE_TYPE' declared here
Q_MOVABLE_TYPE = 0x2,
^
In file included from /Users/user/Downloads/VTK_Examples/SideBySideRenderWindowsQt/build/SideBySideRenderWindowsQt_autogen/mocs_compilation.cpp:2:
In file included from /Users/user/Downloads/VTK_Examples/SideBySideRenderWindowsQt/build/SideBySideRenderWindowsQt_autogen/EWIEGA46WW/moc_SideBySideRenderWindowsQt.cpp:9:
In file included from /Users/user/Downloads/VTK_Examples/SideBySideRenderWindowsQt/build/SideBySideRenderWindowsQt_autogen/EWIEGA46WW/../../../SideBySideRenderWindowsQt.h:6:
In file included from /usr/local/opt/qt/lib/QtWidgets.framework/Headers/QMainWindow:1:
In file included from /usr/local/opt/qt/lib/QtWidgets.framework/Headers/qmainwindow.h:44:
In file included from /usr/local/opt/qt/lib/QtWidgets.framework/Headers/qwidget.h:52:
/usr/local/opt/qt/lib/QtWidgets.framework/Headers/qsizepolicy.h:231:33: error: use of undeclared identifier 'Q_RELOCATABLE_TYPE'; did you mean 'Q_MOVABLE_TYPE'?
Q_DECLARE_TYPEINFO(QSizePolicy, Q_RELOCATABLE_TYPE);
^
/usr/local/include/QtCore/qglobal.h:2272:5: note: 'Q_MOVABLE_TYPE' declared here
Q_MOVABLE_TYPE = 0x2,
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [CMakeFiles/SideBySideRenderWindowsQt.dir/SideBySideRenderWindowsQt_autogen/mocs_compilation.cpp.o] Error 1
make[1]: *** [CMakeFiles/SideBySideRenderWindowsQt.dir/all] Error 2
make: *** [all] Error 2
Similar error I get with cmake -DCMAKE_CXX_COMPILER=g++-8, where g++-8 is installed with brew
Maybe I should mention, there is a software using vtk and qt that I can install via brew without any problems. The same software cannot be compiled directly (cmake --> make).
Could be something with my OS is wrong?
Just uninstall the duplicate QT installations on your system, like the older qt4 version. Credits to khrykin

How to compile a program from .cpp files and a makefile

I recently downloaded a program. A patient specific survival prediction CLI, http://pssp.srv.ualberta.ca/
The readme included states:
"1 Compilation
The code should compile on Linux without any modification. To compile, just type ’make’. There should
be 2 executables after compilation, mtlr train and mtlr test."
I download an extracted the folder to my location, when I go into the directory and type make I get:
x#x-laptop:/pssp_source$ make
g++ -c -O3 DenseVector.cpp -o DenseVector.o
In file included from DenseVector.cpp:1:0:
DenseVector.h:9:2: error: ‘size_t’ does not name a type
size_t m_dim;
^
DenseVector.h:18:21: error: expected ‘)’ before ‘n’
DenseVector(size_t n);
^
DenseVector.h:26:33: error: ‘size_t’ does not name a type
double const& operator[](const size_t i) const
^
DenseVector.h:26:40: error: ISO C++ forbids declaration of ‘i’ with no type [-fpermissive]
double const& operator[](const size_t i) const
^
DenseVector.h:31:27: error: ‘size_t’ does not name a type
double& operator[](const size_t i)
^
DenseVector.h:31:34: error: ISO C++ forbids declaration of ‘i’ with no type [-fpermissive]
double& operator[](const size_t i)
^
DenseVector.h:38:2: error: ‘size_t’ does not name a type
size_t dim() const
^
DenseVector.h: In member function ‘void DenseVector::push_back(double)’:
DenseVector.h:23:3: error: ‘m_dim’ was not declared in this scope
m_dim++;
^
DenseVector.cpp: At global scope:
DenseVector.cpp:6:1: error: prototype for ‘DenseVector::DenseVector(size_t)’ does not match any in class ‘DenseVector’
DenseVector::DenseVector(size_t n): m_dim(n)
^
In file included from DenseVector.cpp:1:0:
DenseVector.h:5:7: error: candidates are: DenseVector::DenseVector(const DenseVector&)
class DenseVector
^
DenseVector.h:12:2: error: DenseVector::DenseVector()
DenseVector(void);
^
DenseVector.cpp: In constructor ‘DenseVector::DenseVector()’:
DenseVector.cpp:16:2: error: class ‘DenseVector’ does not have any field named ‘m_dim’
:m_dim(0)
^
DenseVector.cpp: In member function ‘void DenseVector::clear()’:
DenseVector.cpp:27:22: error: ‘m_dim’ was not declared in this scope
for (size_t i=0; i<m_dim; i++)
^
In file included from /usr/include/c++/4.8/cassert:43:0,
from DenseVector.cpp:3:
DenseVector.cpp: In function ‘double sprod_nn(const DenseVector&, const DenseVector&)’:
DenseVector.cpp:37:11: error: ‘const class DenseVector’ has no member named ‘dim’
assert(a.dim() == b.dim());
^
DenseVector.cpp:37:22: error: ‘const class DenseVector’ has no member named ‘dim’
assert(a.dim() == b.dim());
^
DenseVector.cpp:38:15: error: ‘const class DenseVector’ has no member named ‘dim’
size_t n = a.dim();
^
In file included from /usr/include/c++/4.8/cassert:43:0,
from DenseVector.cpp:3:
DenseVector.cpp: In function ‘void multadd_nn(DenseVector&, const DenseVector&, double)’:
DenseVector.cpp:49:11: error: ‘class DenseVector’ has no member named ‘dim’
assert(w.dim()==a.dim());
^
DenseVector.cpp:49:20: error: ‘const class DenseVector’ has no member named ‘dim’
assert(w.dim()==a.dim());
^
DenseVector.cpp:50:15: error: ‘class DenseVector’ has no member named ‘dim’
size_t n = w.dim();
^
DenseVector.cpp: In function ‘void smult_n(DenseVector&, double)’:
DenseVector.cpp:62:15: error: ‘class DenseVector’ has no member named ‘dim’
size_t n = w.dim();
^
make: *** [DenseVector.o] Error 1
The contents of the folder look like:
x#x-laptop:/pssp_source$ ls
common.cpp data_type_api.h DenseVector.h Main.cpp Makefile Sparm.cpp Sparm.o SparseVector.h test_model.mltr Util.h
common.h DenseVector.cpp example_data Main.o readme.pdf Sparm.h SparseVector.cpp Test.cpp test_model.mlty
I looked up the basic packages needed for compiling c++ code, as well as basics on how to run it and none have gotten me past this issue. It looks as if it has a problem with size_t not having a type.
The start of DenseVector.cpp is :
#include "DenseVector.h"
#include <cassert>
#include <iostream>
DenseVector::DenseVector(size_t n): m_dim(n)
{
m_dvector.reserve(n);
for (size_t i=0; i<n; i++)
{
m_dvector.push_back(0);
}
}
I have never compiled code like this before, so I am probably missing something obvious. If its needed I am running ubuntu 14.04, g++ version is
4.8.4.
Thanks
It sounds like the README lied. Probably it happened to work with a different version of the standard library.
Try adding
#include <stddef.h>
near the top of DenseVector.h.
Open the file DenseVector.h in the root directory of the program and modify it, inserting
#pragma once
#include <vector>
#include <cstddef> // <--- Add this line to the file
class DenseVector
{
protected:
// ...
Save it and try again!
I don't think you are using the correct version of C; I think you need C11. Instead of using the -03 flag, use -11 or -std=c11. Then recompile it.

Qt requires C++11 support" make error

I tried Compile the latest tiled from source code following the instructions in README.md.
My working environment:
tiled source code: tiled-0.16.1
Mac OS: 10.11.1
Xcode : 7.1
QMake: 3.0
Qt: 5.7.0
Apple LLVM: 7.0.0
But the make failed with the following error:
In file included from pythonplugin.cpp:21:
In file included from ./pythonplugin.h:30:
In file included from ../../libtiled/logginginterface.h:33:
In file included from ../../libtiled/tiled_global.h:32:
In file included from /Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qglobal.h:1145:
In file included from /Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qatomic.h:46:
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:61:4: error: "Qt requires C++11 support"
# error "Qt requires C++11 support"
^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:90:13: error: unknown type name 'QAtomicOps'
typedef QAtomicOps<T> Ops;
^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:90:23: error: expected member name or ';' after declaration
specifiers
typedef QAtomicOps<T> Ops;
~~~~~~~~~~~~~~~~~~^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:93:23: error: use of undeclared identifier 'QAtomicOpsSupport'
Q_STATIC_ASSERT_X(QAtomicOpsSupport<sizeof(T)>::IsSupported, "template parameter is an integral of a size not supported on this platform");
^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qglobal.h:746:66: note: expanded from macro 'Q_STATIC_ASSERT_X'
#define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
^
In file included from pythonplugin.cpp:21:
In file included from ./pythonplugin.h:30:
In file included from ../../libtiled/logginginterface.h:33:
In file included from ../../libtiled/tiled_global.h:32:
In file included from /Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qglobal.h:1145:
In file included from /Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qatomic.h:46:
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:93:53: error: no member named 'IsSupported' in the global
namespace
Q_STATIC_ASSERT_X(QAtomicOpsSupport<sizeof(T)>::IsSupported, "template parameter is an integral of a size not supported on this platform");
~~^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qglobal.h:746:66: note: expanded from macro 'Q_STATIC_ASSERT_X'
#define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
^
In file included from pythonplugin.cpp:21:
In file included from ./pythonplugin.h:30:
In file included from ../../libtiled/logginginterface.h:33:
In file included from ../../libtiled/tiled_global.h:32:
In file included from /Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qglobal.h:1145:
In file included from /Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qatomic.h:46:
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:95:14: error: use of undeclared identifier 'Ops'
typename Ops::Type _q_value;
^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:95:19: error: expected a qualified name after 'typename'
typename Ops::Type _q_value;
^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:95:23: error: expected ';' at end of declaration list
typename Ops::Type _q_value;
^
;
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:99:44: error: use of undeclared identifier 'Ops'
T load() const Q_DECL_NOTHROW { return Ops::load(_q_value); }
^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:99:54: error: use of undeclared identifier '_q_value'
T load() const Q_DECL_NOTHROW { return Ops::load(_q_value); }
^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:100:45: error: use of undeclared identifier 'Ops'
void store(T newValue) Q_DECL_NOTHROW { Ops::store(_q_value, newValue); }
^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:100:56: error: use of undeclared identifier '_q_value'
void store(T newValue) Q_DECL_NOTHROW { Ops::store(_q_value, newValue); }
^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:102:51: error: use of undeclared identifier 'Ops'
T loadAcquire() const Q_DECL_NOTHROW { return Ops::loadAcquire(_q_value); }
^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:102:68: error: use of undeclared identifier '_q_value'
T loadAcquire() const Q_DECL_NOTHROW { return Ops::loadAcquire(_q_value); }
^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:103:52: error: use of undeclared identifier 'Ops'
void storeRelease(T newValue) Q_DECL_NOTHROW { Ops::storeRelease(_q_value, newValue); }
^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:103:70: error: use of undeclared identifier '_q_value'
void storeRelease(T newValue) Q_DECL_NOTHROW { Ops::storeRelease(_q_value, newValue); }
^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:107:86: error: use of undeclared identifier 'Ops'
static Q_DECL_CONSTEXPR bool isReferenceCountingNative() Q_DECL_NOTHROW { return Ops::isReferenceCountingNative(); }
^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:107:34: error: no return statement in constexpr function
static Q_DECL_CONSTEXPR bool isReferenceCountingNative() Q_DECL_NOTHROW { return Ops::isReferenceCountingNative(); }
^
/Users/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:108:88: error: use of undeclared identifier 'Ops'
static Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree() Q_DECL_NOTHROW { return Ops::isReferenceCountingWaitFree(); }
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[3]: *** [pythonplugin.o] Error 1
make[2]: *** [sub-python-make_first] Error 2
make[1]: *** [sub-plugins-make_first-ordered] Error 2
make: *** [sub-src-make_first-ordered] Error 2
After doing some research, I tried to add a line CONFIG+= c++11 to the tiled.pro file and then make clean , qmake, make but still I am having the same error ......
tiled.pro :
# Check the Qt version. If QT_VERSION is not set, it is probably Qt 3.
isEmpty(QT_VERSION) {
error("QT_VERSION not defined. Tiled does not work with Qt 3.")
}
include(tiled.pri)
!minQtVersion(5, 1, 0) {
message("Cannot build Tiled with Qt version $${QT_VERSION}")
error("Use at least Qt 5.1.0.")
}
TEMPLATE = subdirs
CONFIG += ordered
CONFIG += c++11
SUBDIRS = src translations
Not sure what goes wrong here.
Any advice will be appreciated, thanks :)
UPDATE:
Tried
QMAKE_CXXFLAGS += -std=c++11
and
QMAKE_CXXFLAGS += -std=c++0x
Still have the same error ......
I thought it might be in the C++ compile the make command use, here is some information :
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c `python-config --cflags` -O2 -std=gnu++11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.8 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -W -fPIC -DPYTHON_LIBRARY -DQT_NO_DEBUG -DQT_PLUGIN -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I../../libtiled -I/Users/supersuraccoon/Qt5.7.0/5.7/clang_64/lib/QtWidgets.framework/Headers -I/Users/supersuraccoon/Qt5.7.0/5.7/clang_64/lib/QtGui.framework/Headers -I/Users/supersuraccoon/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/AGL.framework/Headers -I/Users/supersuraccoon/Qt5.7.0/5.7/clang_64/mkspecs/macx-clang -F/Users/supersuraccoon/Qt5.7.0/5.7/clang_64/lib -o pythonplugin.o pythonplugin.cpp
I had a similar problem building poppler with Qt wrappers and got the same error: "Qt requires C++11 support".
My setup is:
Mac OS: 10.11.5
Xcode : 7.3.1
QMake: 3.0
Qt: 5.7.0
Apple LLVM: 7.3.0
All I did was:
export CXXFLAGS=-std=c++11
./configure
make
and it worked.
I know it has been a while.
How I finally solve this problem is adding in CMakeLists.txt the following line just after project(MyProject):
add_compile_options(-std=c++11)
That says to cmake, to create a Makefile that will use c++11 solving issues.

Working with external library in C++ (SVL library)

I tried to install the external library SVL, that is given in the link. I did make install and it seems now I can import it as given in documentation using #include <svl/some_header_files.h>
Now I want to run some of my program to test. But I am struggling with it. I did
g++ vertex.hh vertex.cc
the program I want to work and it gives out,
In file included from vertex.hh:9:
In file included from /usr/local/include/svl/Vec3.h:14:
/usr/local/include/svl/Vec2.h:25:10: error: unknown type name 'Real'
Vec2(Real x, Real y); // (x, y)
^
/usr/local/include/svl/Vec2.h:25:18: error: unknown type name 'Real'
Vec2(Real x, Real y); // (x, y)
^
/usr/local/include/svl/Vec2.h:27:10: error: unknown type name 'ZeroOrOne'
Vec2(ZeroOrOne k); // v[i] = vl_zero
^
/usr/local/include/svl/Vec2.h:28:10: error: unknown type name 'Axis'
Vec2(Axis k); // v[k] = 1
^
/usr/local/include/svl/Vec2.h:32:5: error: unknown type name 'Real'
Real &operator [] (Int i);
^
/usr/local/include/svl/Vec2.h:32:31: error: unknown type name 'Int'; did you mean 'int'?
Real &operator [] (Int i);
and more similar errors, which is then followed by
In file included from vertex.cc:10:
In file included from /usr/local/include/svl/Vec3.h:14:
/usr/local/include/svl/Vec2.h:25:10: error: unknown type name 'Real'
Vec2(Real x, Real y); // (x, y)
^
/usr/local/include/svl/Vec2.h:25:18: error: unknown type name 'Real'
Vec2(Real x, Real y); // (x, y)
^
/usr/local/include/svl/Vec2.h:27:10: error: unknown type name 'ZeroOrOne'
Vec2(ZeroOrOne k); // v[i] = vl_zero
^
and more similar errors,
and in the end,
/usr/local/include/svl/Vec2.h:69:27: error: unknown type name 'Int'; did you mean 'int'?
Vec2 &MakeUnit(Int i, Real k = vl_one); // I[i]
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
Can you tell me what is going on here? How can i fix this?
Here is the link to the two files vertex.ccand vertex.hh
https://www.dropbox.com/sh/4cax5ftk2lssots/AAA62m2VnSZXqBfB65VfVqFTa?dl=0
New error using #include "svl/SVL.h"
In file included from vertex.hh:13:
./edge.hh:289:10: warning: unelaborated friend declaration is a C++11 extension; specify 'class' to befriend 'QuadEdge'
[-Wc++11-extensions]
friend QuadEdge;
^
class
1 warning generated.
In file included from vertex.cc:12:
In file included from ./cell.hh:9:
./edge.hh:289:10: warning: unelaborated friend declaration is a C++11 extension; specify 'class' to befriend 'QuadEdge'
[-Wc++11-extensions]
friend QuadEdge;
^
class
In file included from vertex.cc:12:
./cell.hh:293:10: warning: unelaborated friend declaration is a C++11 extension; specify 'class' to befriend 'CellVertexIterator'
[-Wc++11-extensions]
Why are you compiling vertex.hh? Why not just
g++ vertex.cc
Secondly, can you show us the contents of your header file and source file. Actually, the source file can probably be:
#include "vertex.hh"
int main() { return 0; }
and the header file:
#include "svl/SVL.h"
Secondly, when you say "#include " are you just including some of SVL internal headers? That may not work. http://www.cs.cmu.edu/~ajw/doc/svl.html says "for basic use, the only header file needed is svl/SVL.h".