Skip to content

Commit 29afdd9

Browse files
author
Ian Eyberg
committed
adding instructions to manually include libresolv if needed
1 parent 71cabb0 commit 29afdd9

File tree

5 files changed

+72
-12
lines changed

5 files changed

+72
-12
lines changed

cpp/01-hello-world/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
C++ Hello World
2+
================
3+
4+
Compile C++ code:
5+
6+
```sh
7+
gcc main.cpp -lstdc++ -o app.exe
8+
```
9+
10+
Run with ops:
11+
12+
```sh
13+
ops run app.exe
14+
```
File renamed without changes.

cpp/02-dns/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
C++ Hello World
2+
================
3+
4+
Depending on your libc version and your distro of choice you'll want to
5+
include libresolv (you might not have to do this on newer versions):
6+
7+
```sh
8+
cc main.cpp -o main
9+
```
10+
11+
config.json:
12+
```sh
13+
{
14+
"Files": ["/usr/lib/x86_64-linux-gnu/libresolv.so.2"]
15+
}
16+
```
17+
18+
If you're unsure you can do a
19+
20+
```
21+
ops run --trace main &>/tmp/out
22+
```
23+
24+
and grep for library load failures. Most OPS packages auto-include this
25+
for interpreted languages and other newer compiled languages deal with
26+
this differently.
27+
28+
```
29+
ops run -c config.json main
30+
```

cpp/02-dns/main.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <sys/types.h>
2+
#include <stdlib.h>
3+
#include <sys/socket.h>
4+
#include <netinet/in.h>
5+
#include <arpa/inet.h>
6+
#include <netdb.h>
7+
#include <stdio.h>
8+
9+
int main(int argc, char *argv[])
10+
{
11+
12+
struct hostent *hp;
13+
struct in_addr ip_addr;
14+
15+
const char *host = "dns.google";
16+
17+
hp = gethostbyname(host);
18+
if (!hp) {
19+
printf("was not resolved\n");
20+
}
21+
22+
ip_addr = *(struct in_addr *)(hp->h_addr);
23+
printf("Hostname: dns.google, was resolved to: %s\n",
24+
inet_ntoa(ip_addr));
25+
26+
exit(EXIT_SUCCESS);
27+
28+
}

cpp/README.md

-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,2 @@
11
C++ Hello World
22
================
3-
4-
Compile C++ code:
5-
6-
```sh
7-
gcc main.cpp -lstdc++ -o app.exe
8-
```
9-
10-
Run with ops:
11-
12-
```sh
13-
ops run app.exe
14-
```

0 commit comments

Comments
 (0)