Problem with setting up opengl on ubuntu with visual studio code [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 days ago.
Improve this question
I am having issues when I try to set up opengl up in linux using vs code, I keep getting this message in the console without it actually telling me what the error is:
Starting build...
/usr/bin/g++ -g -std=c++17 -I./include -L./lib src/\*.cpp src/glad.c -lglfw3dll -o -lGL
-lglfw -ldl
spawn /bin/sh ENOENTBuild finished with error(s).
my tasks.json is setup like this:
"args": [
"-g",
"-std=c++17",
"-I./include",
"-L./lib",
"src/\\*.cpp",
"src/glad.c",
"-o",
"-lGL",
"-lglfw",
"-ldl"
]
Below is also a pricture of my file structure if it is useful for figuring out what the problem is.
Filestructure
Furthermore the code in myprogram.cpp is taken from the Hello Window section from LearnOpenGL here is a link to the source code: Source code. Just say if I have forgotten to add any information that you would need.

Related

How to add C++ flag -Wno-unused-function on cmake? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I added on my CMakeLists.txt on Android:
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable -Wno-unused-function -Wno-error")
but I get multiple errors like this:
error: unused function 'createParserError' [-Werror,-Wunused-function]
There's nothing that could rewrite CMAKE_CXX_FLAGS.
With modern cmake, you can use add_compile_options and target_compile_options instead of setting the variable directly
Thus in your context you can write
add_compile_options(" -Wno-unused-variable -Wno-unused-function -Wno-error")
to add the compile options to all targets or simply
target_compile_options(LIBRARY_NAME SCOPE "-Wno-unused-variable -Wno-unused-function -Wno-error")
to set those options for one target.
If you need it to be cross platform
if(${PLATFORM_1})
add_compile_options("WARNING_FLAGS_FOR_PLATFORM1")
elseif(${PLATFORM_2})
add_compile_options("WARNING_FLAGS_FOR_PLATFORM2")
endif()
replace the variable by your required values

How to configure VSCode task to compile multiple files on Linux?

I have a project to compile in VSCode that consists of multiple source files and want to add a single argument to my task that would tell g++ to link all files with .cpp extension. The following does not work:
"args": [
"${workspaceFolder}/*.cpp*",
...
g++: error: /home/kirusfg/Study/Programming/CSCI 152/Assignments/Assignment 4/*.cpp*: No such file or directory,
even though
g++ '/home/kirusfg/Study/Programming/CSCI 152/Assignments/Assignment 4/*.cpp*' -o main-optimized.out -g -O5 -flto -Wreturn-type -pedantic -pedantic-errors -Wundef -std=c++17
works perfectly if entered via terminal.
Seems to me you are having issues with space in your 'workspaceFolder' path, "args" field not handling spaces well.
It seems like your best option is to add the arg to the "command" field.
i.e.:
...
"command": "g++ ${workspaceFolder}/*.cpp*",
"args":[],
...
I hope it will fix your issue.
Reference:
See closed issue from VScode GitHub: How to pass arguments with space to tasks correctly

Porting Java package to C++ and using Cmake as a build tool [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I have the following task. There is a java package that needs to be ported to c++17. A transpiling tool is being used to help with the task and avoid manual rewrite of every single file. Currently for all java classes/interfaces the corresponding c++ class is being created.
The first problem I see with this is that the original java package is huge and it has more then 180 folders. Those all are replicated in the new c++ code-base. We would like to use Cmake as a build tool but the very first problem we see is that we can not simply split the project in multiple sub-directories and simply build separate shared libraries in each sub directory since those have dependencies on each other, and I am really afraid of ending up with circular dependency.
I know it is a lot to ask here but still, what would be the best practice (if any exists) on how to organize such port form java to c++ with cmake. We would like to keep the folder structure since it is logical. The only solution I see so far is to build one giant target that depends on everything.
Any comments and ideas or examples of such structure are highly appreciated.
You could structure the build so that the end result is indeed a giant target including everything, but the subcomponents that go into that build are specified in a piecewise fashion that would put the settings closer to their sources.
As a basic example, I set up a test project with
base CMakeLists.txt:
cmake_minimum_required(VERSION 3.14)
project(cmake_test)
add_library(megalib SHARED dummy.cpp)
add_subdirectory(a)
add_subdirectory(b)
a/CMakeLists.txt:
target_include_directories(megalib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_sources(megalib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/a.cpp)
b/CMakeLists.txt:
target_include_directories(megalib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_sources(megalib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/b.cpp)
And the resulting compilation log (using the Ninja generator):
[1/4] /usr/bin/c++ -Dmegalib_EXPORTS -I/tmp/cmake-test/a -I/tmp/cmake-test/b -fPIC -MD -MT CMakeFiles/megalib.dir/dummy.cpp.o -MF CMakeFiles/megalib.dir/dummy.cpp.o.d -o CMakeFiles/megalib.dir/dummy.cpp.o -c /tmp/cmake-test/dummy.cpp
[2/4] /usr/bin/c++ -Dmegalib_EXPORTS -I/tmp/cmake-test/a -I/tmp/cmake-test/b -fPIC -MD -MT CMakeFiles/megalib.dir/a/a.cpp.o -MF CMakeFiles/megalib.dir/a/a.cpp.o.d -o CMakeFiles/megalib.dir/a/a.cpp.o -c /tmp/cmake-test/a/a.cpp
[3/4] /usr/bin/c++ -Dmegalib_EXPORTS -I/tmp/cmake-test/a -I/tmp/cmake-test/b -fPIC -MD -MT CMakeFiles/megalib.dir/b/b.cpp.o -MF CMakeFiles/megalib.dir/b/b.cpp.o.d -o CMakeFiles/megalib.dir/b/b.cpp.o -c /tmp/cmake-test/b/b.cpp
[4/4] : && /usr/bin/c++ -fPIC -shared -Wl,-soname,libmegalib.so -o libmegalib.so CMakeFiles/megalib.dir/dummy.cpp.o CMakeFiles/megalib.dir/a/a.cpp.o CMakeFiles/megalib.dir/b/b.cpp.o && :
It might then be useful to set up some macros to reduce the amount of repetition between subdirectories. (Especially to reduce the burden of having to specify an absolute file path for every source file you add in a subdirectory.)

Compiling C++11 in Visual Studio Code [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I'm using Visual Studio Code to compile C++ programs and it works for most C++ programs as it compiles it using g++ command. However, I am facing difficulty in compiling c++11 programs using it.
When I try compiling C++11 programs, the compiler command g++ tries to compile it using default C++98 Standard and this results in errors.
I am aware that using g++ -std=c++11, we can compile C++11 programs using g++ and it works fine when I use it in my cmd as:
g++ -std=c++11 some_program.cpp
I wish I could tweak some setting in Visual Studio Code and change the compiler command from g++ to g++ -std=c++11 so that I could compile programs by just hitting the run code button. However, I'm not able to find one. Please help me out if there are alternate ways to get my program compiled.
Currently, I'm getting errors as:
some_program.cpp: In function 'int main()':
some_program.cpp:12:33: error: in C++98 'A' must be initialized by constructor, not by '{...}'
vector A = { 11,2,3,14 };
The snippets are correct and have been tested with online compilers using C++11. Here, it is trying to compile using C++98 as seen in the error.
Go to Settings > User Settings
In here, search for Run Code Configuration:
Under this menu, find:
"code-runner.executorMap"
Edit this Setting by adding it to User Setting as below for C++11 support:
"code-runner.executorMap":{
"cpp": "cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
},
OR
Edit this Setting by adding it to User Setting as below for C++17 support:
"code-runner.executorMap":{
"cpp": "cd $dir && g++ -std=c++17 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
},
Hope this helps !

how to setup and use openGL? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 months ago.
Improve this question
I use mingW for compiling c++ code. I want to make graphics using openGL. I use notepad++ for writing code. So how can I use the libraries of openGL?
In MinGW you don't have to setup OpenGL. Already there is OpenGL library in a directory C:\~\MinGW\include\GL.Just include the GL/gl.h and GL/glu.h and write code for your OpenGL project.But if you are looking GLUT,GLFW,glew or other library then using the IDE is better soluton like code::blocks or visual studio then do google to setup these library for your IDE.
Once you've got your OpenGL projects compiling and are maybe wondering what do do next, NeHe has a series of great OpenGL tutorials: http://nehe.gamedev.net/
From memory, they are all related to immediate mode (pre v3.0), but a good place to start - especially if you'd rather not use other libraries like GLUT for licensing reasons.
There is a also good list of tutorials here:
http://www.opengl.org/wiki/Getting_Started#Tutorials_and_How_To_Guides
By the way, you can download the Express edition of Visual C++, which is free. Just in case you're only avoiding the Microsoft compiler because of cost: http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express
It's just a cut-back version of the professional edition. Basically it doesn't have OpenMP, MFC or ATL, some more advanced debugging tools, and won't compile 64-bit apps. But otherwise it's great. The only thing I'd be upset about not having is 64-bit and OpenMP. But it's free! Feature comparison is here: http://msdn.microsoft.com/en-us/library/hs24szh9.aspx
OpenGL Text Editor/No IDE Friendly
After you write a .cpp files in Notepad,Notepad++,VS Code,Vim,Etc.
You can compile the .cpp file and generate a executable using MinGW on command line with the following command.
g++ ./main.cpp -o./main
Linking all the Opengl Project's files and libraries can quickly turn command line into looking like this
g++ /path/main.cpp /path/another.cpp... -I/path/includedlibirary... -L/path/headers... -lglfw3 -lopengl32 -lglu32 -lgdi32 -o/path/output_executable
IMG:What it what eventually looks like in command line
Instead of typing a similar monstrosity before every compile
I would use a Makefile and add it in the same directory as your project.Then compile the Makefile with following command.
mingw32-make
A Makefile
Acts like a Batch script
Acts like a linker in Codeblocks or Visual Studio: linking files and libraries to compiler
Can tell the compiler where to output the executable .exe
IMG:Example of OpenGL Project Directory
Note: File paths are based on my setup and project's setup
Example Makefile:
# Created Libraries directory in C: to store downloaded libraries
glfw_include = C:\Libraries\GLFW\include
glfw_lib = C:\Libraries\GLFW\lib
glad_include = C:\Libraries\GLAD\include
glad_src = C:\Libraries\GLAD\src\glad.c
stb_include = C:\Libraries\STB\include
stb_src = C:\Libraries\STB\src\stb.cpp
glm_include = C:\Libraries\GLM\include
json_include = C:\Libraries\JSON\include
# Project's local header files
local_include = ./Header
# Project's local cpp files
local_src = ./Source/shaders_class.cpp ./Source/textures_class.cpp ./Source/camera_class.cpp ./Source/meshes_class.cpp ./Source/model_class.cpp ./Source/shaders_EBO.cpp ./Source/shaders_VAO.cpp ./Source/shaders_VBO.cpp
################################################################################################################################################################################################################################
CXX = g++
CPP = ./Source/main.cpp
TARGET = ./Bin/main
OBJECTS = $(CPP) $(glad_src) $(stb_src) $(local_src)
INCLUDES = -I$(glfw_include) -I$(glad_include) -I$(stb_include) -I$(glm_include) -I$(json_include) -I$(local_include)
LIBRARIES = -L$(glfw_lib)
C_FLAGS = $(INCLUDES)
LD_FLAGS = $(LIBRARIES) -lglfw3 -lopengl32 -lglu32 -lgdi32
$(TARGET): $(CPP) # Final Output
# Puts everything together in string that auto runs on command line
# '''Ex: g++ <cpp files> -I<included> -L<header_files> -lglfw3 -lopengl32 -lglu32 -lgdi32 -o<output executable>'''
$(CXX) $(OBJECTS) $(C_FLAGS) $(LD_FLAGS) -o$(TARGET)
Example output from Makefile
g++ ./Source/main.cpp C:\Libraries\GLAD\src\glad.c C:\Libraries\STB\src\stb.cpp ./Source/shaders_class.cpp ./Source/textures_class.cpp ./Source/camera_class.cpp ./Source/meshes_class.cpp ./Source/model_class.cpp ./Source/shaders_EBO.cpp ./Source/shaders_VAO.cpp ./Source/shaders_VBO.cpp -IC:\Libraries\GLFW\include -IC:\Libraries\GLAD\include -IC:\Libraries\STB\include -IC:\Libraries\GLM\include -IC:\Libraries\JSON\include -I./Header -LC:\Libraries\GLFW\lib -lglfw3 -lopengl32 -lglu32 -lgdi32 -o./Bin/main
Credit To:
Recommend for linking files to MinGW / Creating Makefile
Sonars Systems: SDL 2 Tutorial 1c [SETUP] Windows and MinGW Setup
https://www.youtube.com/watch?v=ybYMOKEW9IY&t=15s
Recommend OpenGL Intro
Victor Gordan: OpenGL Tutorials
https://www.youtube.com/playlist?list=PLPaoO-vpZnumdcb4tZc4x5Q-v7CkrQ6M-