How to add C++ flag -Wno-unused-function on cmake? [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 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

Related

Problem with setting up opengl on ubuntu with 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 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.

What is the difference between CMAKE_CXX_FLAGS_RELEASE (cmake release flag) values? [duplicate]

This question already has answers here:
What's the difference between -O3 and (-O2 + flags that man gcc says -O3 adds to -O2)?
(2 answers)
Closed 12 months ago.
I was working with CMake. I have seen many CMake files and found there is a different release flag value set.
In one file I found:
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
In another:
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
and in other I found:
set(CMAKE_CXX_FLAGS_RELEASE "-O1")
Please let me know what is the exact difference between these flags values? Can I use any one?
You can read about those flags here
And shortly -O0, -O1, -O2, -O3 differ with the optimization level at the compile time. -O3 includes optimizations which are specified by -O2. And -O2 includes optimizations which are specified by -O1.
In your projects you can use any of those. You can even use no one of those flags (by default compiler uses -O0 flag).
But in the university I was taught to use -O2 or -O3.

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.)

What does the clang++ -c flag do? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
What does the -c flag do in the following command?
clang++ -std=c++11 -g -Wall -stdlib=libc++ -isystem testing/gtest-1.7.0/include -Itesting/gtest-1.7.0 -pthread -c testing/gtest-1.7.0/src/gtest-all.cc
I've looked for the flag in the documentation (http://clang.llvm.org/docs/UsersManual.html), as well as in the help message (clang -cc1 --help)...can't seem to find the answer.
The -c flag is used to tell the compiler you don't want to build a program (link together into an executable), just compile this particular file into an object file - typically producing a file called something.o or something.obj - in this case gteger-all.cc
(Note that this flag is common with nearly all compilers available - from Turbo C from 1990's to the latest versions of MS, Gnu and LLVM/Clang)
man clang++
OPTIONS
Stage Selection Options
-E Run the preprocessor stage.
-fsyntax-only
Run the preprocessor, parser and type checking stages.
-S Run the previous stages as well as LLVM generation and optimization stages and target-specific code generation, producing an assembly file.
-c Run all of the above, plus the assembler, generating a target ".o" object file.
man clang is your friend!
OPTIONS
Stage Selection Options
-E Run the preprocessor stage.
-fsyntax-only
Run the preprocessor, parser and type checking stages.
-S Run the previous stages as well as LLVM generation and optimization
stages and target-specific code generation, producing an assembly
file.
-c Run all of the above, plus the assembler, generating a target ".o"
object file.

How to enable a specific gcc warnings for a specific directory or file? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Selectively disable GCC warnings for only part of a translation unit?
How to enable a specific gcc warnings for a specific directory or file ?
I want to enable -Wsign-conversion for my own files not for any other system headers
This line should do it: (see here)
#pragma GCC diagnostic warning "-Wsign-conversion"
Put it in the affected files or in a header that is included in all you files
If you want to do it outside of your source file, then you need to reference your build system. E.g. in make you can always specify a direct target in the Makefile:
foo.o: foo.c
$(CC) -o $> -Wsign-conversion $<
This will take precedence to a general .c->.o rule as it is more more specific.
Other build systems have other methods of achieving the same rule.
In short, your question is really about your build system, and not about gcc.