pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/bazelbuild/bazel/commit/a65ce6d547ee36f7d1fbeb81105d22849193371f

f1e80bb.css" /> Update example of building dll on Windows · bazelbuild/bazel@a65ce6d · GitHub
Skip to content

Commit a65ce6d

Browse files
meteorcloudyCopybara-Service
authored andcommitted
Update example of building dll on Windows
Closes #7252. Change-Id: I9bc2d80deda291d3818c690fc3b36aacf62e0830 PiperOrigin-RevId: 233564393
1 parent f21ee4d commit a65ce6d

File tree

5 files changed

+74
-14
lines changed

5 files changed

+74
-14
lines changed

examples/windows/dll/BUILD

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,66 @@ filegroup(
44
visibility = ["//examples:__pkg__"],
55
)
66

7+
cc_library(
8+
name = "hello-library-header",
9+
hdrs = ["hello-library.h"],
10+
)
11+
712
cc_binary(
813
name = "hellolib.dll",
914
srcs = [
1015
"hello-library.cpp",
1116
],
17+
# Define COMPILING_DLL to export symbols during compiling the DLL.
18+
# See hello-library.h
19+
copts = ["/DCOMPILING_DLL"],
1220
linkshared = 1,
21+
deps = [
22+
":hello-library-header",
23+
],
1324
)
1425

26+
# **Explicitly link to hellolib.dll**
27+
28+
# Declare hellolib.dll as data dependency and load it explicitly in code.
1529
cc_binary(
16-
name = "hello",
30+
name = "hello_world-load-dll-at-runtime",
1731
srcs = [
18-
"hello-world.cpp",
32+
"hello_world-load-dll-at-runtime.cpp",
1933
],
2034
data = [":hellolib.dll"],
2135
)
36+
37+
# **Implicitly link to hellolib.dll**
38+
39+
# Get the import library for hellolib.dll
40+
filegroup(
41+
name = "hello_lib_import_lib",
42+
srcs = [":hellolib.dll"],
43+
output_group = "interface_library",
44+
)
45+
46+
# Because we cannot directly depend on cc_binary from other cc rules in deps attribute,
47+
# we use cc_import as a bridge to depend on hellolib.dll
48+
cc_import(
49+
name = "hellolib_dll_import",
50+
interface_library = ":hello_lib_import_lib",
51+
shared_library = ":hellolib.dll",
52+
)
53+
54+
# Create a new cc_library to also include the headers needed for hellolib.dll
55+
cc_library(
56+
name = "hellolib_dll",
57+
deps = [
58+
":hello-library-header",
59+
":hellolib_dll_import",
60+
],
61+
)
62+
63+
cc_binary(
64+
name = "hello_world-link-to-dll-via-lib",
65+
srcs = [
66+
"hello_world-link-to-dll-via-lib.cpp",
67+
],
68+
deps = [":hellolib_dll"],
69+
)
Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
#include <stdio.h>
2+
#include <time.h>
23
#include <windows.h>
34

4-
#ifdef __cplusplus
5-
extern "C" {
6-
#endif
7-
8-
#include <time.h>
5+
#include "examples/windows/dll/hello-library.h"
96

10-
__declspec(dllexport) char *get_time() {
7+
DLLEXPORT char *get_time() {
118
time_t ltime;
129
time(&ltime);
1310
return ctime(&ltime);
1411
}
1512

16-
__declspec(dllexport) void say_hello(char *message) {
13+
DLLEXPORT void say_hello(char *message) {
1714
printf("Hello from dll!\n%s", message);
1815
}
19-
20-
#ifdef __cplusplus
21-
}
22-
#endif
23-
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef HELLO_LIBRARY_H
2+
#define HELLO_LIBRARY_H
3+
4+
#ifdef COMPILING_DLL
5+
#define DLLEXPORT __declspec(dllexport)
6+
#else
7+
#define DLLEXPORT __declspec(dllimport)
8+
#endif
9+
10+
extern "C" DLLEXPORT char *get_time();
11+
extern "C" DLLEXPORT void say_hello(char *);
12+
13+
#endif
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "examples/windows/dll/hello-library.h"
2+
3+
int main() {
4+
char *now = get_time();
5+
say_hello(now);
6+
return 0;
7+
}
File renamed without changes.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy