move c++ demo in separate file

add newline to printf
This commit is contained in:
swaldhoer 2020-04-22 15:31:58 +02:00
parent c7b2a5628e
commit 371d4410a5
5 changed files with 829 additions and 820 deletions

8
demos/c++/c.cpp Normal file
View File

@ -0,0 +1,8 @@
#include <iostream>
extern void foo();
int main() {
printf("%s\n", HELLO_WORLD);
return 0;
}

View File

@ -4,6 +4,5 @@ extern void foo();
int main() {
foo();
printf("%s", HELLO_WORLD);
return 0;
}

View File

@ -21,8 +21,9 @@ def build(bld):
bld.shlib(source='a.cpp', target='mylib', vnum='9.8.7')
bld.shlib(source='a.cpp', target='mylib2', vnum='9.8.7', cnum='9.8')
bld.shlib(source='a.cpp', target='mylib3')
bld.program(source='main.cpp', target='app', include_files='file-include/inc-file/header.h', use='mylib')
bld.program(source='main.cpp', target='app', use='mylib')
bld.stlib(target='foo', source='b.cpp')
bld.program(source='c.cpp', target='file-include', include_files='file-include/inc-file/header.h', use='mylib')
# just a test to check if the .c is compiled as c++ when no c compiler is found
bld.program(features='cxx cxxprogram', source='main.c', target='app2')

View File

@ -2,6 +2,6 @@
int main()
{
printf("%s", HELLO_WORLD);
printf("%s\n", HELLO_WORLD);
return 0;
}

View File

@ -132,6 +132,7 @@ def apply_incfiles(self):
tg = bld(features='include_files', include_files='my-header.h')
The files need to be given relative to the current directory.
This method will add a list of header file nodes to ``tg.env.INCFILES``.
"""
node_lst = []
@ -142,9 +143,9 @@ def apply_incfiles(self):
node_lst.append(self.path.find_node(x))
cwd = self.get_cwd()
if self.env.CXX_NAME == "msvc":
# This is necessary as CL.exe running in CPP-mode can not handle relative includes.
# In C-mode however it can, but handling C and CPP sources different makes things more
# complicated, and like this way it works fine.
# CL.exe treats file includes relative to the source file. So either we calculate the relative
# file include path for each source file, or we just do it once using absolute paths, which is
# simpler and just works.
self.env.INCFILES = [x.abspath() for x in node_lst if x.is_file()]
else:
self.env.INCFILES = [x.path_from(cwd) for x in node_lst if x.is_file()]