Hi I am trying to build a compile_commands.json on windows with Scons build system and all other possibilities have failed.
I decided to use the Clang -MJ option to do this as this seems the easiest solution available.
The issue is that it isnt clear how I would go about doing this with the Scons build system; Basically I have to add -MJ myfilename.o.json to every build command. I am currently building a Library with multiple sources files like this :
library = env.StaticLibrary(target=result_path + '/' + result_name, source=sources)
Essentially at the end I should have : clang++ -target x86_64-pc-windows-gnu -MJ AABB.o.json -o src/core/AABB.o -c -m64 -g -O3 -std=c++14 -Wwrite-strings -I. -I/c/GodotLibraries/godot_headers -Iinclude -Iinclude/core src/core/AABB.cpp
Thanks in advance,
`
You are trying to set special compiler flags for your current build environment. This is done by appending the new flags to the correct environment variable. Depending on what build process (=Builder) you want to use, the corresponding single build actions (=Actions) might use different variables. The User Guide contains an Appendix A "Construction Variables", listing the default variables and their synopsis.
In your case the CCFLAGS is relevant and can be used like this:
env = Environment()
env.Append(CCFLAGS=['-MJ','AAB.o.json','-m64','-g','-O3'])
env.Program(...)
In the same way you can make SCons use the clang compiler, by setting the CXX variable accordingly:
env = Environment()
env['CXX']='clang'
env.Append(CCFLAGS=['-MJ','AAB.o.json','-m64','-g','-O3'])
env.Program(...)
I hope this lets you get the general idea behind the Builder/Action setup in SCons: The basic structure of the executed command is always the same for each Builder, but you can influence the final output by setting and overwriting those environment variables that get expanded.
As of SCons 4.0.0, you can have SCons build the compilation database like this:
env.Tool('compilation_db')
env.CompilationDatabase('compile_commands.json')
Related
I use meson 0.53.2 on ubuntu 20.04.
I would like to have a maximally optimized executable (-Ofast) but contain all debug symbols (-g3)
If I use --buildtype=release it optimizes -O2 and the executable contains no debug symbol.
If I use --buildtype=debug it does not optimize at all and uses -g.
If I use --buildtype=debugoptimized it optimizes -O2 and uses -g.
I tried to use --debug which seems not to work, because the executable does not contain any debug symbol. Instead if I use -Ddebug=true the debug symbols are there but with the flag -g.
So how do I get gcc to compile with -Ofast -g3 flags in the least dirty way possible?
From the commandline, you can switch higher level of optimization with option optimization=3. It gives you -O3 instead -O2.
By editing meson script, you can set any flags.
if get_option('buildtype') == 'custom'
add_project_arguments('-Ofast', '-g3', language : 'cpp')
endif
And in case you cannot modify meson script, you may alter environment variables
CXXFLAGS="-Ofast -g3" meson --buildtype=custom build_c
And --reconfigure seems to not see environment variables.
While compiling some libraries (spatialite 3.0.1, geos 3.3.3 and others) I've noticed that running ./configure results in a makefile that contains lines like this
CFLAGS = -g -O2
CXXFLAGS = -g -O2
That means that debug symbol generation is enabled by default. What I want is to disable debug compiling mode without manual makefile editing. I've ran ./configure --help for both of libraries mentioned above, but I have not found any option to get desired result. I feel that the solution should be very simple, but I'm stuck on this since I'm not very familiar with building software from sources.
OS: Linux Red Hat Enterprise 6
Assuming you're talking about autoconf/automake:
Why not just keep the debugging symbols and let anybody who doesn't like them make install-strip?
You can pass CFLAGS and CXXFLAGS along with configure script
./configure CFLAGS="-O2" CXXFLAGS="-O2"
My gcc compiler is at a custom location /my/path/hpgcc
I've downloaded the boost sources. Executed bootstrap.sh, but it fails because it runs with the default gcc.
Looking into it, I see that it fails at the first thing it does: building the Boost.Build engine:
gcc -o bootstrap/jam0 command.c compile.c debug.c expand.c glob.c hash.c hdrmacro.c headers.c jam.c jambase.c jamgram.c lists.c make.c make1.c newstr.c option.c output.c parse.c pathunix.c pathvms.c regexp.c rules.c scan.c search.c subst.c timestamp.c variable.c modules.c strings.c filesys.c builtins.c pwd.c class.c native.c md5.c w32_getreg.c modules/set.c modules/path.c modules/regex.c modules/property-set.c modules/sequence.c modules/order.c execunix.c fileunix.c
(fails because executed with the default gcc, and not my gcc version).
I've tried to change the gcc path in the user-config.jam file, but it doesn't help. Probably because the Boost.Build's build script boost_1_47_0/tools/build/v2/engine/build.sh doesn't use user-config.jam, and just uses the default locations.
Any solution?
Add the line:
using gcc : : /my/path/hpgcc ;
to user-config.jam. user-config.jam will usually be in /path/to/boost/tools/build/v2/, but you can put a custom user-config.jam or site-config.jam in any of the places listed here.
/my/path/hpgcc should be the full path to the g++ executable.
EDIT (Igor Oks) : What eventually solved the problem is that I edited boost_1_47_0/tools/build/v2/engine/build.sh to make it use my custom gcc.
We do this in our build environment by simply defining the PATH and LD_LIBRARY_PATH environment variables to pickup our desired GCC first.
I am attempting to install an application. During compilation it fails with the following error:
/usr/bin/ld: cannot find -lemu
I have installed the libemu library, and it now currently resides in /opt/libemu/. However, when I try and compile my application the library is not found. Is there any way to correct this?
EDIT: It also looks like the make is resulting in:
It also looks like the make file is compiling with the following:
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions
build/temp.linux-x86_64-2.6/libemu_module.o
-L/opt/libemu/lib -lemu -o build/lib.linux-x86_64-2.6/libemu.so
I have tried setting my LD_LIBRARY_PATH to /opt/libemu, still doesn't work - fails with the error mentioned above.
You need to tell the linker where it is:
gcc stuff -L/opt/libemu -lemu
or:
gcc stuff /opt/libemu/libemu.a
where stuff is your normal compile/link options files etc.
You can also specify library paths in the LIBRARY_PATH environment variable:
LIBRARY_PATH=/opt/libemu
export LIBRARY_PATH
before you run your build. Yet another option is to see where gcc looks for libraries by running:
gcc --print-search-dirs
and put your library in one of the listed directories.
Edit: It is really not clear from your latest info what you are trying to build. Are you trying to turn a static library into a shared library? Most important - What is the exact filename of the library file you have copied into the /opt/libemu directory?
The environment variable LD_LIBRARY_PATH should include (but probably does not by default) /opt/libemu.
try running:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/libemu
make install
I'm trying to compile C/C++ code from an external source using SciTE. The SciTE has a built-in feature where it searches for the gcc compiler and libraries in the same folder. The problem occurs if I try to compile from SciTE externally. Compiling with F5 (compile and run) or CTRL-F7 (compile) results in SciTE not being able to find the compiler.
I'm wondering if there is a way (there always is) to embed the gcc compiler's path into one of SciTE's files without generally rewriting SciTE's code?
EDIT: Found a solution in Linux.
I used MinGW as an external source to compile in C and C++ code in scite.
If you do not have MinGW you can get MinGW here: http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/
mingw may have problems if installed into directories containing spaces.
After installing MinGW add the bin directory to sysytem path environment variables.
Go to Control pannel.
System
Advanced system settings
Click on the Environment Variables tab
Add the MinGW's bin directory to the path system variables list.
Default directory: "C:\MinGW\bin"
In scite:
Open cpp.properties
Search for: cc=g++ $(ccopts) -c $(FileNameExt) -o $(FileName).o
Change the g++ part to MinGW's bin directory plus compiler exe ex:
cc=C:\MinGW\bin\g++.exe $(ccopts) -c $(FileNameExt) -o $(FileName).o
For gcc compiling change ccc=gcc.exe $(ccopts) -c $(FileNameExt) -o $(FileName).o to ccc=C:\MinGW\bin\gcc $(ccopts) -c $(FileNameExt) -o $(FileName).o
Now search for command.go.$(file.patterns.cplusplus)=./$(FileName)
Change it to command.go.$(file.patterns.cplusplus)=$(FileName).exe
For gcc compiling search for command.go.*.c=./$(FileName) and change it similarly.
Save the changes to file
Please note that you may have to change permissions in the scite folder before you will be able to save the changes to cpp.properties
Your code will now be able to compile (use shift+F7) and run(F5).
Go to options -> cpp.properties -> goto line 303 or find the following line:
cc=g++ $(ccopts) -c $(FileNameExt) -o $(FileName).o
next line will be for gcc option.
Now set full path for gcc or g++ as follows,
ccc=D:\Dev-Cpp\bin\gcc.exe $(ccopts) -c $(FileNameExt) -o $(FileName).o
In the above line D:\Dev-Cpp\bin\gcc.exe is the path for gcc on my system. You can do the similar thing by editing the path according to your own installation of gcc. Once set write a program and compile.
Note: There are other options for you to set for example the standard to use for compiling your programs.
I hope it helps.