SOLVED! = instead of - in the CMakeLists.txt in say-hello directory
I have problems with defining a preprocessor variable with CMake according to vector-of-bool's CMake-Tutorial https://www.youtube.com/watch?v=SYgESCQeGJY&list=PLK6MXr8gasrGmIiSuVQXpfFuE1uPT615s&index=8.
Obviously, I am using a different CMake-Version than the one that he's using in the video. But before changing my version I want to tackle the problem here.
After configuring successfully via cmake .., I run make and receive the following:
[ 25%] Building CXX object say-hello/CMakeFiles/say-hello.dir/src/say-hello/hello.cpp.o
<command-line>:0:14: warning: ISO C++11 requires whitespace after the macro name
/home/maximilian/Dokumente/02_Programmieren/VSCMAKE/say-hello/src/say-hello/hello.cpp: In function ‘void hello::say()’:
<command-line>:0:17: error: expected ‘;’ before numeric constant
/home/maximilian/Dokumente/02_Programmieren/VSCMAKE/say-hello/src/say-hello/hello.cpp:7:43: note: in expansion of macro ‘HELLO_VERSION’
std::cout << "Hello (Version " << HELLO_VERSION << ")\n";
^~~~~~~~~~~~~
say-hello/CMakeFiles/say-hello.dir/build.make:62: recipe for target 'say-hello/CMakeFiles/say-hello.dir/src/say-hello/hello.cpp.o' failed
make[2]: *** [say-hello/CMakeFiles/say-hello.dir/src/say-hello/hello.cpp.o] Error 1
CMakeFiles/Makefile2:90: recipe for target 'say-hello/CMakeFiles/say-hello.dir/all' failed
make[1]: *** [say-hello/CMakeFiles/say-hello.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
I am using:
Linux
g++ 8.1
C++11
CMake 3.14.4
Visual Studio Code
Top CMakeLists.txt
cmake_minimum_required(VERSION 3.14.4)
project(MyProject VERSION 1.0.0)
set(CMAKE_CXX_STANDARD 11)
add_subdirectory(say-hello)
add_subdirectory(mainsrc)
CMakeLists.txt in mainsrc
add_executable(main.out main.cpp)
target_link_libraries(main.out PRIVATE say-hello)
main.cpp
#include <iostream>
#include <say-hello/hello.hpp>
int main(){
hello::say();
return 0;
}
CMakeLists.txt in say-hello
add_library(say-hello
src/say-hello/hello.cpp
src/say-hello/hello.hpp
)
target_include_directories(say-hello PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_compile_definitions(say-hello PUBLIC HELLO_VERSION-4)
hello.hpp
#ifndef HELLO
#define HELLO
//#define SAYHELLOVERSION 4
namespace hello{
void say();
}
#endif
hello.cpp
#include <iostream>
#include "hello.hpp"
namespace hello{
void say(){
//int version = SAYHELLOVERSION;
std::cout << "Hello (Version " << HELLO_VERSION << ")\n";
}
}
Related
I get this message upon compiling with cmake:
In file included from scanner.lex:6:
C:\Users\uriya\CLionProjects\untitled1\output.hpp:4:10: fatal error: string: No such file or directory
4 | #include <string>
| ^~~~~~~~
compilation terminated.
make.exe[3]: *** [CMakeFiles\untitled1.dir\build.make:88: CMakeFiles/untitled1.dir/lex.yy.c.obj] Error 1
make.exe[3]: *** Waiting for unfinished jobs....
make.exe[2]: *** [CMakeFiles\Makefile2:72: CMakeFiles/untitled1.dir/all] Error 2
make.exe[1]: *** [CMakeFiles\Makefile2:84: CMakeFiles/untitled1.dir/rule] Error 2
make.exe: *** [Makefile:117: untitled1] Error 2
This is the part of the code that causes the problems:
#ifndef _236360_2_
#define _236360_2_
#include <string>
using namespace std;
namespace output {
extern const string rules[];
void printProductionRule(int ruleno);
void errorLex(int lineno);
void errorSyn(int lineno);
};
#endif
and that's the cmake input:
cmake_minimum_required(VERSION 3.13)
project(untitled1)
set(CMAKE_CXX_STANDARD 11)
add_executable(untitled1 parser.tab.cpp output.cpp lex.yy.c)
oddly enough I manage to compile it with no problems using g++ -std=c++11 -o hw2 parser.tab.cpp output.cpp lex.yy.c
what's the difference between cmake and this command?
This is the root of my project. I think I am missing a basic concept because the error occur when I wrap the the find() function in a struct.
CMakeLists.txt
bst.cpp
bst.hpp
bst-test.cpp
catch.hpp
CMakeLists.txt
cmake_minimum_required(VERSION 3.16.4 FATAL_ERROR)
project(bst LANGUAGES CXX)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_library(bst bst.cpp)
add_executable(bst-test bst-test.cpp)
target_link_libraries(bst-test bst)
enable_testing()
add_test(
NAME catch_test
COMMAND $<TARGET_FILE:bst-test> --success
)
bst.cpp
struct Bst {
int find(int num, int array[]) { return -1; }
};
bst.hpp
struct Bst {
int find(int num, int array[]);
};
bst-test.cpp
#include "bst.hpp"
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
TEST_CASE("The number to search is not found in the list", "[notFound]") {
int array[]{};
Bst tree;
REQUIRE(tree.find(1, array) == -1);
}
This is the error when trying to compile.
CMakeFiles/bst-test.dir/bst-test.cpp.o: In function `____C_A_T_C_H____T_E_S_T____0()':
bst-test.cpp:(.text+0x2b0b5): undefined reference to `Bst::find(int, int*)'
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
CMakeFiles/bst-test.dir/build.make:84: recipe for target 'bst-test' failed
make[2]: *** [bst-test] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/bst-test.dir/all' failed
make[1]: *** [CMakeFiles/bst-test.dir/all] Error 2
Makefile:94: recipe for target 'all' failed
make: *** [all] Error 2
you are declaring the Bst structure again in your .cpp file. The source file should only contain the definition of the methods, not the declaration of the structure.
Changing bst.cpp to the following fixes the error:
#include "bst.hpp"
int Bst::find(int num, int array[]) { return -1; }
I have seens some answers, but most of them does not work for me. So I would like to make everything clear by adding a new question, my CMakeLists.txt is like this:
cmake_minimum_required(VERSION 3.17)
project(example)
include_directories(./)
link_directories(./)
if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Os -g ${CMAKE_CXX_FLAGS}")
message("CMAKE_COMPILER_IS_GNUCXX is True")
message("option is: ${CMAKE_CXX_FLAGS}")
endif (CMAKE_COMPILER_IS_GNUCXX)
add_executable(main try.cpp)
target_link_libraries(main fun)
set_property(TARGET main PROPERTY POSITION_INDEPENDENT_CODE 1 LINK_FLAGS -pie)
add_library(fun SHARED func.cpp)
# target_compile_options(fun PUBLIC "-pie")
target_link_libraries(fun PUBLIC "-pie")
set_property(TARGET fun PROPERTY POSITION_INDEPENDENT_CODE 1)
And the source code for try.cpp is:
#include<iostream>
#include "func.hpp"
int main() {
using namespace std;
cout << "hello from exe main" << endl;
func();
return 0;
}
The code for fun.cpp and fun.hpp is like this:
// func.hpp
void func();
// func.cpp
#include <iostream>
using std::cout;
using std::endl;
void func() {
cout << "hell from so func\n";
}
int main() {
cout << "hello from so main\n";
return 0;
}
My problem is that: I got the following link error when I compile it with cmake:
Scanning dependencies of target fun
[ 25%] Building CXX object CMakeFiles/fun.dir/func.cpp.o
[ 50%] Linking CXX shared library libfun.so
[ 50%] Built target fun
Scanning dependencies of target main
[ 75%] Building CXX object CMakeFiles/main.dir/try.cpp.o
[100%] Linking CXX executable main
/usr/bin/ld: CMakeFiles/main.dir/try.cpp.o: in function `main':
/home/coin/learn-coding/projects/C/cmake/try.cpp:8: undefined reference to `func()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/main.dir/build.make:105: main] Error 1
make[1]: *** [CMakeFiles/Makefile2:125: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:104: all] Error 2
What is the problem with the configuration and how could I make it work ?
By the way, I tried to compile with command line:
g++ -fPIC -pie func.cpp -o libfun.so -shared
g++ try.cpp -o main -L. -lfun
Which does work when I run the generated main, but the generated so file cannot be runnable:
$ ./main
hello from exe main
hell from so func
$ ./libfun.so
Segmentation fault (core dumped)
What did I miss here ?
The following files based on this answer:
cat >CMakeLists.txt <<EOF
cmake_minimum_required(VERSION 3.17)
project(example)
if(CMAKE_COMPILER_IS_GNUCXX)
add_compile_options(
$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>
-Wall
-Os
-g
)
endif()
add_executable(main try.cpp)
target_link_libraries(main PRIVATE fun)
add_library(fun SHARED func.cpp)
target_link_options(fun PRIVATE -Wl,-e,entry_point)
EOF
cat >func.cpp <<EOF
// func.hpp
void func();
// func.cpp
#include <iostream>
using std::cout;
using std::endl;
void func() {
cout << "hell from so func\n";
}
static inline
int lib_main() {
printf("hello from so main\n");
return 0;
}
extern "C" const char interp_section[] __attribute__((section(".interp"))) = "/lib64/ld-linux-x86-64.so.2";
extern "C" void entry_point()
{
lib_main();
exit(0);
}
EOF
cat >try.cpp <<EOF
#include<iostream>
void func();
int main() {
using namespace std;
cout << "hello from exe main" << endl;
func();
return 0;
}
EOF
when compiled with the following on my 64-bit system with glibc, it generates two files that are executable:
$ cmake -S . -B _build && cmake --build _build -- VERBOSE=1
balbla compilation output
$ _build/main
hello from exe main
hell from so func
$ _build/libfun.so
hello from so main
I replaced std::cout with printf because I received a segmentation fault - I suspect global constructors are not beeing run and something in iostream destructors makes it go segfault.
I think adding LINK_FLAGS -pie) and target_link_libraries(fun PUBLIC "-pie") makes no point, it's handled with POSITION_INDEPENDENT_CODE property and I guess for shared library it's TRUE anyway (but I am not sure about that).
I'am trying to cross-compile the simplest DCMTK example I found and I can get it built.
I am running Ubuntu 18.04.4 LTS to cross compile using x86_64-w64-mingw32.
I have checked these answers and examples too, but they didn't work for me:
CMake: Cross-compiling linux-to-windows with MinGW does not find some system headers
https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/cross_compiling/Mingw
This is the only file of the project (main.cpp):
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
using namespace std;
int main()
{
DcmFileFormat fileformat;
OFCondition status = fileformat.loadFile("sample.dcm");
if (status.good())
{
OFString patientName;
if (fileformat.getDataset()->findAndGetOFString(DCM_PatientName, patientName).good())
{
cout << "Patient's Name: " << patientName << endl;
} else
cerr << "Error: cannot access Patient's Name!" << endl;
OFString patientID;
if (fileformat.getDataset()->findAndGetOFString(DCM_PatientID, patientID).good())
{
cout << "Patient's ID: " << patientID << endl;
} else
cerr << "Fatal Error: cannot access Patient's ID!" << endl;
} else
cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;
return 0;
}
This is my CMake.txt configuration file:
cmake_minimum_required(VERSION 2.8)
PROJECT(test1DCMTK)
add_executable(${PROJECT_NAME} "main.cpp")
SET(DCMTK_DIR /usr/local/include/dcmtk)
ADD_DEFINITIONS(-D_REENTRANT)
INCLUDE_DIRECTORIES(${DCMTK_DIR}/include)
LINK_DIRECTORIES(${DCMTK_DIR}/lib)
TARGET_LINK_LIBRARIES(test1DCMTK ofstd dcmdata)
And I am using this toolchain file:
### CMAKE cross compile settings for Windows running from Ubuntu 18.04.4 LTS x86_x64 amd64 ###
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Windows)
SET(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
SET(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc-posix)
SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++-posix)
#SET(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
# which compilers to use for C and C++
#SET(CMAKE_C_COMPILER x86_x64-mingw32-gcc)
#SET(CMAKE_CXX_COMPILER x86_x64-mingw32-g++)
###SET(CMAKE_RC_COMPILER i586-mingw32msvc-windres)
# here is the target environment located
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX} /usr/lib/gcc/${TOOLCHAIN_PREFIX}/7.3-posix)
# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
When I configure, with CMake, I get this:
The C compiler identification is GNU 7.3.0
The CXX compiler identification is GNU 7.3.0
Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc-posix
Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc-posix -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++-posix
Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++-posix -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Configuring done
But when I try to build the code, this is what I get:
/home/yo/Projects/test1DCMTK/main.cpp:1:10: fatal error: dcmtk/config/osconfig.h: No existe el archivo o el directorio
#include "dcmtk/config/osconfig.h"
^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
CMakeFiles/test1DCMTK.dir/build.make:63: fallo en las instrucciones para el objetivo 'CMakeFiles/test1DCMTK.dir/main.cpp.obj'
make[2]: *** [CMakeFiles/test1DCMTK.dir/main.cpp.obj] Error 1
CMakeFiles/Makefile2:67: fallo en las instrucciones para el objetivo 'CMakeFiles/test1DCMTK.dir/all'
make[1]: *** [CMakeFiles/test1DCMTK.dir/all] Error 2
Makefile:83: fallo en las instrucciones para el objetivo 'all'
make: *** [all] Error 2
However, the library exists:
(base) yo#MiPC:/usr/local/include/dcmtk/config$ ls /usr/local/include/dcmtk/config/os*
/usr/local/include/dcmtk/config/osconfig.h
So, what am I doing wrong? What should I do to get it working properly?
I tried the answer of #squareskittles, and I got this when tried to build:
(base) yo#MiPC:~/Projects/build-test1DCMTK-win32$ make all
-- Configuring done
-- Generating done
-- Build files have been written to: /home/yo/Projects/build-test1DCMTK-win32
Scanning dependencies of target test1DCMTK
[ 50%] Building CXX object CMakeFiles/test1DCMTK.dir/main.cpp.obj
In file included from /usr/local/include/dcmtk/dcmdata/dcistrma.h:28:0,
from /usr/local/include/dcmtk/dcmdata/dctk.h:30,
from /home/elekta/Projects/QT/TUTOS-QT/test1DCMTK/main.cpp:2:
/usr/local/include/dcmtk/ofstd/offile.h:74:9: error: ‘fpos64_t’ does not name a type; did you mean ‘fpos_t’?
typedef fpos64_t offile_fpos_t;
^~~~~~~~
fpos_t
/usr/local/include/dcmtk/ofstd/offile.h:866:15: error: ‘offile_fpos_t’ has not been declared
int fgetpos(offile_fpos_t *pos)
^~~~~~~~~~~~~
/usr/local/include/dcmtk/ofstd/offile.h:886:15: error: ‘offile_fpos_t’ has not been declared
int fsetpos(offile_fpos_t *pos)
^~~~~~~~~~~~~
/usr/local/include/dcmtk/ofstd/offile.h: In member function ‘int OFFile::fseek(offile_off_t, int)’:
/usr/local/include/dcmtk/ofstd/offile.h:757:5: error: ‘offile_fpos_t’ was not declared in this scope
offile_fpos_t off2 = off;
^~~~~~~~~~~~~
/usr/local/include/dcmtk/ofstd/offile.h:757:5: note: suggested alternative: ‘offile_off_t’
offile_fpos_t off2 = off;
^~~~~~~~~~~~~
offile_off_t
/usr/local/include/dcmtk/ofstd/offile.h:792:9: error: ‘off2’ was not declared in this scope
off2 += buf.st_size;
^~~~
/usr/local/include/dcmtk/ofstd/offile.h:792:9: note: suggested alternative: ‘off’
off2 += buf.st_size;
^~~~
off
/usr/local/include/dcmtk/ofstd/offile.h:808:29: error: ‘off2’ was not declared in this scope
result = this->fsetpos(&off2);
^~~~
/usr/local/include/dcmtk/ofstd/offile.h:808:29: note: suggested alternative: ‘off’
result = this->fsetpos(&off2);
^~~~
off
/usr/local/include/dcmtk/ofstd/offile.h: In member function ‘offile_off_t OFFile::ftell()’:
/usr/local/include/dcmtk/ofstd/offile.h:837:5: error: ‘offile_fpos_t’ was not declared in this scope
offile_fpos_t pos;
^~~~~~~~~~~~~
/usr/local/include/dcmtk/ofstd/offile.h:837:5: note: suggested alternative: ‘offile_off_t’
offile_fpos_t pos;
^~~~~~~~~~~~~
offile_off_t
/usr/local/include/dcmtk/ofstd/offile.h:838:24: error: ‘pos’ was not declared in this scope
if (this->fgetpos(&pos) != 0)
^~~
/usr/local/include/dcmtk/ofstd/offile.h:838:24: note: suggested alternative: ‘pow’
if (this->fgetpos(&pos) != 0)
^~~
pow
/usr/local/include/dcmtk/ofstd/offile.h:843:12: error: ‘pos’ was not declared in this scope
return pos;
^~~
/usr/local/include/dcmtk/ofstd/offile.h:843:12: note: suggested alternative: ‘pow’
return pos;
^~~
pow
/usr/local/include/dcmtk/ofstd/offile.h: In member function ‘int OFFile::fgetpos(int*)’:
/usr/local/include/dcmtk/ofstd/offile.h:873:48: error: cannot convert ‘int*’ to ‘fpos_t* {aka long long int*}’ for argument ‘2’ to ‘int fgetpos(FILE*, fpos_t*)’
result = STDIO_NAMESPACE fgetpos(file_, pos);
^
/usr/local/include/dcmtk/ofstd/offile.h: In member function ‘int OFFile::fsetpos(int*)’:
/usr/local/include/dcmtk/ofstd/offile.h:893:48: error: cannot convert ‘int*’ to ‘const fpos_t* {aka const long long int*}’ for argument ‘2’ to ‘int fsetpos(FILE*, const fpos_t*)’
result = STDIO_NAMESPACE fsetpos(file_, pos);
^
CMakeFiles/test1DCMTK.dir/build.make:63: fallo en las instrucciones para el objetivo 'CMakeFiles/test1DCMTK.dir/main.cpp.obj'
make[2]: *** [CMakeFiles/test1DCMTK.dir/main.cpp.obj] Error 1
CMakeFiles/Makefile2:67: fallo en las instrucciones para el objetivo 'CMakeFiles/test1DCMTK.dir/all'
make[1]: *** [CMakeFiles/test1DCMTK.dir/all] Error 2
Makefile:83: fallo en las instrucciones para el objetivo 'all'
make: *** [all] Error 2
Your CMake is adding the dcmtk include directories like this:
SET(DCMTK_DIR /usr/local/include/dcmtk)
INCLUDE_DIRECTORIES(${DCMTK_DIR}/include)
which evaluates to this path:
/usr/local/include/dcmtk/include
Your main.cpp file then includes dcmtk/config/osconfig.h, which (combining the two paths) suggests the header is located here:
/usr/local/include/dcmtk/include/dcmtk/config/osconfig.h
This doesn't seem correct. Try including only /usr/local/include in your CMake file instead:
INCLUDE_DIRECTORIES(/usr/local/include)
As a side note, CMake provides a Find Module for the DCMTK, so it will attempt to find the library and set some variable for you. You could try something like this, but depending on your CMake version, you may have varying results:
cmake_minimum_required(VERSION 2.8)
PROJECT(test1DCMTK)
find_package(DCMTK REQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
SET(DCMTK_DIR /usr/local/include/dcmtk)
ADD_DEFINITIONS(-D_REENTRANT)
# Use the INCLUDE_DIRS variable populated by the DCMTK find module.
INCLUDE_DIRECTORIES(${DCMTK_INCLUDE_DIRS})
# Use the LIBRARIES variable populated by the DCMTK find module.
TARGET_LINK_LIBRARIES(test1DCMTK ofstd ${DCMTK_LIBRARIES})
If this successfully finds DCMTK, the DCMTK_INCLUDE_DIRS will likely contain all necessary include directories for DCMTK, not only the include directory you have added manually. This may help resolve the compiler errors you are seeing.
This question already has answers here:
Error with multiple definitions of function
(4 answers)
Closed 4 years ago.
I am trying to compile a simple code using cmake and I getting an error. The code and cmake file are as below. The test.cpp is the main file in which i have directly included test1.cpp. I have also included my CMake file and the error that I am getting on performing make.
test.cpp
#ifndef _IOSTREAM_
#include<iostream>
#endif
#include"test1.cpp"
using namespace std;
int main()
{
printing("hello");
return 0;
}
test1.cpp
#ifndef _IOSTREAM_
#include<iostream>
#endif
#include<string>
using namespace std;
void printing(string s)
{
cout<<s<<endl;
return;
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
set(CMAKE_C_COMPILER "/usr/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
project(test)
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -std=c++11)
add_executable(test test.cpp test1.cpp)
Error
CMakeFiles/test.dir/test1.cpp.o: In function
printing(std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >):
/home/vatsal/Desktop/test/test1.cpp:(.text+0x0): multiple definition
of printing(std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >)
CMakeFiles/test.dir/test.cpp.o:/home/vatsal/Desktop/test/test.cpp:
(.text+0x0): first defined here
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
CMakeFiles/test.dir/build.make:98: recipe for target test failed
make[2]: *** [test] Error 1
CMakeFiles/Makefile2:67: recipe for target CMakeFiles/test.dir/all
failed
make[1]: *** [CMakeFiles/test.dir/all] Error 2
Makefile:83: recipe for target all failed
make: *** [all] Error 2
It happens because include cpp file is a bad idea.
After preprocessor work you'll get two defenition of void printing(string s) The first one is in test.cpp because you've incleded test1.cpp and the second one is in test1.cpp.
Solution is to create test1.h which contain declaration of function:
#include<iostream>
#include<string>
using namespace std;
void printing(string s);
Then fix test1.cpp:
#include "test1.h"
using namespace std;
void printing(string s)
{
cout<<s<<endl;
return;
}
And finaly replace #include"test1.cpp" with #include"test1.h" in test.cpp