-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cpp: rewrite example to have library, binary, and test (#243)
A single file is too simple.
- Loading branch information
Showing
5 changed files
with
48 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
cc_binary( | ||
name = "cpp", | ||
srcs = ["main.cc"], | ||
deps = [":cpp_lib"], | ||
) | ||
|
||
cc_library( | ||
name = "cpp_lib", | ||
srcs = [ | ||
"hello.cc", | ||
"hello.h", | ||
], | ||
) | ||
|
||
cc_test( | ||
name = "cpp_test", | ||
srcs = ["hello_test.cc"], | ||
deps = [":cpp_lib"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "cpp/hello.h" | ||
|
||
#include <string> | ||
|
||
std::string hello() { | ||
return "hello"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef cpp_hello_h | ||
#define cpp_hello_h | ||
|
||
#include <string> | ||
|
||
std::string hello(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <iostream> | ||
#include "cpp/hello.h" | ||
|
||
int main() { | ||
auto got = hello(); | ||
if (got != "hello") { | ||
std::cerr << "got '" << got << "', want 'hello'" << std::endl; | ||
return 1; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
#include <stdio.h> | ||
|
||
int main(int argc, char** argv) { | ||
printf("Hello World\n"); | ||
} | ||
#include <iostream> | ||
#include "cpp/hello.h" | ||
|
||
int main() { | ||
std::cout << hello() << std::endl; | ||
return 0; | ||
} |