unable to run cpp file using scons - c++

i am trying to compile a c++ program in scons.
the scons works fine for c program but for c++ its giving the following error.
please can anybody help me about this, who knows about this?
first.cpp
#include <iostream>
int main()
{
std::cout << "hellooo" << std::endl;
return 0;
}
SConstructor
Program('first','first.cpp')
the error:
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
o first.o -c first.cpp
sh: o: command not found
o first.exe first.o
sh: o: command not found
scons: done building targets.
what could be the problem in this?

You dont have a compiler for C++ installed, or at least SCons cant find it. Although you would expect SCons to explicitly tell you it cant find the compiler, I think what actually happens is it has a Construction Variable for the compiler that is actually empty, and it uses that to create the command line.
If you do indeed have it installed, you can fix this problem as follows:
env = Environment()
env.Replace(CXX = "/path/to/the/c++/compiler")

Related

clang++ always generates empty profraw coverage reports

I'm trying to integrate coverage in C++ with clang 6 for the first time and have been following this guide.
I successfully compiled the binary, generated a .profraw file and generated a .profdata file as described in steps 1, 2 and 3a. But when I try to create a line-oriented coverage report as described in 3b, I receive the following message:
error: build/debug/dane: Failed to load coverage: No coverage data found
Upon checking the .profraw file, I found it was empty. I tried changing my code a bit and running again but the generated .profraw was always empty.
My main.cpp file:
#include <iostream>
int main(int argc, char **argv) {
std::cout << "Hello, World!" << std::endl;
return 0;
}
My SConstruct file:
env = Environment(CXX='clang++', CXXFLAGS=['-Wall', '-g', '-O0'], LINKFLAGS=['-fprofile-instr-generate', '-fcoverage-mapping'])
env.Program(target='build/debug/dane', source=['src/main.cpp'])
Command line output:
➤ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
clang++ -o src/main.o -c -Wall -g -O0 src/main.cpp
clang++ -o build/debug/dane -fprofile-instr-generate -fcoverage-mapping src/main.o
scons: done building targets.
➤ build/debug/dane
Hello, World!
➤ llvm-profdata merge -sparse default.profraw -o default.profdata
➤ llvm-cov show build/debug/dane -instr-profile=default.profdata
error: build/debug/dane: Failed to load coverage: No coverage data found
I expected the default.profraw file to hold meaningful coverage results, and have no clue why it's empty.
Finally solved it.
At first I gave the -fprofile-instr-generate -fcoverage-mapping flags as CXXFLAGS, but it didn't work, and so I understood that these were linker flags and moved them to the LINKFLAGS (which resulted in this frustrated post).
Apparently, these flags need to appear both as compilation and linker flags in order for the whole thing to work.
I also tried checking if you can distribute the flags between the compiler and the linker but that didn't succeed.

problem with run a c++ code with eclipse che on ubuntu

run eclipse che by browser in ubuntu
when i run this code
#include <iostream>
main() {
std::cout << "Hello World!";
return 0; }
i got this error
cd /projects/my_prj && make && ./a.out
make: *** No targets specified and no makefile found. Stop.
what can i do for solve it?
To test that the required tooling is installed, try running this in the terminal:
cd /projects/my_prj
g++ -o a.out main.cc
(or whatever you called the C++ file you wrote above).
If you want a Makefile to build the project, you will need to specify a target (the default target will be "all") which has a rule for compiling the C++ code into a binary. The minimum would be something like this:
all:
g++ main.cc
Put this in a file called Makefile, and make sure that the 2nd line starts with a real tab, not an expanded one, and you should be good. There is a lot more to learn about Makefiles, but this will get you started.

scons env.InstallAs() doesn't seem to copy any file?

For example, I've a .c file as below:
$cat hello.c
int main(){
return 0;
}
Then I use scons to build and copy it to some place:
$cat SConstruct
import os,sys
env = Environment()
hello = env.Program('hello.c')
env.InstallAs('/home/admin/hello-new', hello)
run scons under user named 'admin' it prints:
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o hello.o -c hello.c
gcc -o hello hello.o
scons: done building targets.
Then I tried to "ls /home/admin" there's no such a thing like "hello-new". So I wonder why my "env.InstallAs()" worked at all? How to trouble-shoot and fix it?
Thanks.
Please read the FAQ, this is a common misunderstanding about SCons and thus in the FAQ:
https://scons.org/faq.html#How_do_I_install_files.3F_The_Install.28.29_method_doesn.27t_do_anything._In_general.2C_how_do_I_build_anything_outside_my_current_directory.3F
With your example changing to this should cause it to always build the target in question:
import os,sys
env = Environment()
hello = env.Program('hello.c')
install_target = env.InstallAs('/home/admin/hello-new', hello)
# Always build the install target by default
Default(install_target)

g++ #include file not found compiler error

I'm currently trying to simply link a file called main.cpp with boost in order to do asio(asynchronous input and output). I'm using a makefile in order to compile the C++ code into executable form. However, despite using the -I modifier on my terminal command in Mac OS X, it still cannot find the appropriate directory to search in. Here is my code in Main
#include <asio.hpp>
int main(){
return 1;
}
and here is the makefile command that I am using
all:
g++ -Iboost_1_60_0/boost/ -o main main.cpp
In my file structure, boost_1_60_0, main.cpp, and makefile are all on the top level, where asio is in the folder boost which is in the folder boost_1_60_0. I'm very confused about this and any help would be appreciated! Thanks!
EDIT: Full error is
1 error generated.
make: *** [all] Error 1
iMats-2:SerialC++ wfehrnstrom$ make
g++ -Iboost_1_60_0 -o main main.cpp
main.cpp:2:10: fatal error: 'asio.hpp' file not found
You should use -Iboost_1_60_0 (or, better still, install Boost properly so that it's found automatically under /usr/include/), and write #include <boost/asio.hpp>.
The include directives inside Boost itself will assume this form, so…
BTW, this has nothing to do with exceptions. Presumably it's a compiler error you've seen.

Scons and dmd error: unrecognized file extension o

I am trying to build a "hello world" D project with SConstruct and getting this output:
D:\projects\test>scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: warning: No version of Visual Studio compiler found - C/C++ compilers most likely not set correctly
File "C:\Python27\Scripts\scons.py", line 192, in <module>
scons: Building targets ...
dmd -I. -c -ofsrc\main.o src\main.d
dmd -ofhello.exe src\main.o
Error: unrecognized file extension o
scons: *** [hello.exe] Error 1
scons: building terminated because of errors.
Further I discovered that dmd compiler generates object files with the *.obj extension, rather then *.o and it is not able to handle with *.o files.
Is there a way to make SCons to use default output for dmd object files or to pass *.obj files extension for them? Or this is just a bug?
My SConstruct file:
import os
env = Environment(ENV=os.environ)
env.Object(target = 'hello', source = 'src/main.d')
My platform is Windows 7 x86_64.
dmd vervion is 2.064.2.
You need to tell SCons to use the D compiler, as I dont believe it does so by default. This does more than just load the compiler, it also sets the corresponding Construction Variables, which among other things sets the object file extension that you are asking about.
If you create your environment as follows, then the D compiler and related construction variables will be loaded.
env=Environment(tools=['default', 'dmd'])