compile opengl red book 9 example - opengl

I have taken from github the red book examples.
Under debian jessie I run cmake and all it is ok.
When I run make I get this error:
In file included from /usr/include/c++/4.9/cstdint:35:0,
from /home/antonio/Documenti/CG/OGLPG-9th- Edition/lib/vdds.cpp:16:
/usr/include/c++/4.9/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.
. . .

Add this line in the CmakeLists.txt file:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++0x")

Related

How to find and provide C++ library headers for clang?

I've built LLVM and Clang from sources using following instruction in order to try some of the latest C++ features.
When I try to compile basic C++ program using this clang I get errors about missing basic headers:
% /usr/local/bin/clang++ -std=c++20 main.cpp
In file included from main.cpp:1:
main.cpp:3:10: fatal error: 'array' file not found
#include <array>
I similarly have brew installed clang, which works perfectly.
The instruction mentions providing C++ library headers to clang, but I don't understand:
How to locate those?
How to make sure, that they are also up to date to support latest C++ features?
I have MacOS Monterey 12.4
You should specify a path to the sdk for your target platform.
You can retreive this by relying on xcrun:
/usr/local/bin/clang++ -isysroot $(xcrun --show-sdk-path) -std=c++20 main.cpp
In case you want to target other platforms (in the example bellow, for iphone) you have to specify both the target triple and the path to the appropiate sdk:
/usr/local/bin/clang++ -target arm64-apple-ios -isysroot $(xcrun --sdk iphoneos --show-sdk-path) -std=c++20 main.cpp
There is also an alternative to the -isysroot option. You could set up the SDKROOT environment variable to point to the target sdk path:
export SDKPATH=$(xcrun --show-sdk-path)
/usr/local/bin/clang++ -std=c++20 main.cpp

How to make CMake use clang for CUDA to support c++17

According to this question, it is possible to use c++17 with cuda by using clang. However, I couldn't find how to setup CMakeLists.txt to accomplish this.
I enable c++17 with
add_compile_options(-std=c++17)
Out of the box with the following
enable_language(CUDA)
nvcc complains
nvcc fatal : Value 'c++17' is not defined for option 'std'
Adding the following as suggested here
set(CUDA_HOST_COMPILER clang++)
set(CMAKE_CUDA_COMPILER /usr/bin/clang++)
clang to complain
clang: error: language not recognized: 'cu'
Try
set(CMAKE_CXX_STANDARD 17)

In XCode clang 11 I get: No template named 'initializer_list' in namespace 'std'

When someone on my team executes:
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake .. -G Xcode
using XCode 10, and then opens the xcodeproj folder, Xcode starts and everything compiles.
In his project.pbxproj file are:
OTHER_CPLUSPLUSFLAGS = "-std=c++11 -pthread -fstrict-aliasing -Wall -Wcast-qual -Wextra -Wformat -Wpedantic -Wswitch-default -Wno-unknown-pragmas
OTHER_LDFLAGS = " -Wl,-search_paths_first -Wl,-headerpad_max_install_names $HEAD/sdsp/metrics/test/build/sws-metrics/Release/libsws-metrics.a";
When I do the same thing using:
Apple clang version 11.0.0 (clang-1100.0.33.17)
it does not compile. I get errors:
No template named 'initializer_list' in namespace 'std'
A space is required between consecutive right angle brackets (use '> >')
And my OTHER variables are blank.
I tried setting my OTHER variables to be like his- it didn't help.
In the project I tried all the various options for
Apple Clang - Language
C Language Dialect - Compiler Default, c11, gnu11
Apple Clang - Language - C++
C++ Language Dialect - C++11 [-std=c++11] (and gnu11 and the 14 and 17's)
C++ Standard Library - Compiler Default, libstdc++, libc++
Apple Clang - Warnings - C++
Using C++11 extensions in earlier versions of C++ - was No and I tried that and Yes
Nothing works.
We both create the makefiles from the same folder with:
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake .. -G Xcode
Any idea what to do?
====
See a sample project on https://randy.strausses.net/info/be

CMake 3.x + CUDA - compilation busted

I've written the following groundbreaking GPU-powered application:
int main() { return 0; }
and I'm trying to build it using CMake. Here's my CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} " -std=c++11" )
find_package(CUDA QUIET REQUIRED)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} " -std=c++11")
cuda_add_executable(a a.cu)
With this file, and for some reason, the compilation fails; it looks like (although I'm not sure) the reason is that CMake is having NVCC use the CUDA include directory twice. The result:
/home/joeuser/opt/cuda/bin/nvcc -M -D__CUDACC__ /home/joeuser/src/kt3/a.cu -o /home/joeuser/src/kt3/CMakeFiles/a.dir//a_generated_a.cu.o.NVCC-depend -ccbin /usr/bin/ccache -m64 --std c++11 -Xcompiler ,\"-g\" -std=c++11 -DNVCC -I/home/joeuser/opt/cuda/include -I/home/joeuser/opt/cuda/include
nvcc fatal : redefinition of argument 'std'
CMake Error at a_generated_a.cu.o.cmake:207 (message):
Error generating
/home/joeuser/src/kt3/CMakeFiles/a.dir//./a_generated_a.cu.o
You might be asking why my MWE is not more terse. Why do I need those option-setting lines above if I don't use C++11 anyway? Well, if I remove them, I still get the double-include, but have an earlier failure involving ccache about which I will probably ask another question.
So is the problem actually the double-include, or is it something else? And what should I do?
Additional information:
I don't have root on this machine.
CMake version: 3.3.2 .
Distribution: Fedora 22 (sorry, I can't help it; but I also seem to be getting this on Debian Stretch as well).
CUDA install location: $HOME/opt/cuda , and its binary directory is in $PATH.
On another system, with a different configuration and distro (Fedora 20, CUDA 7.5 but in another local dir, possibly other differences) I do not get this behavior.
I think the problem is that the nvcc flags are propagated to your c/c++ compiler, so some compiler arguments are effectively passed twice. Try using SET(CUDA_PROPAGATE_HOST_FLAGS OFF)

Why random header not importing

I have written code in C++ and compiled it by typing make. An error occurs:
/usr/include/c++/4.8/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.
you need to add "-std=c++11" to your compiler arguments, telling it that it is a C++11 compile
$ g++ -std=c++11 your_file.cpp -o your_program
If you are using some IDE, you need to search the documentation to find out how to add this line so the compiler knows.
The random library is using a newer version of the C++ standard (C++11). You need to modify your makefile to use the -std=c++11 flag. If you post your makefile contents I could advise you further, otherwise look at this question: Makefile modification to support c++11
Based on the cmakefile posted, add these lines to your cmakefile:
set_property(TARGET abc PROPERTY CXX_STANDARD 11)
set_property(TARGET abc PROPERTY CXX_STANDARD_REQUIRED ON)