Skip to content

Commit 4807e56

Browse files
asinghvi17giordano
andauthored
Add "bare" C and C++ build tips docs (#1371)
* Update build_tips.md Adds brief descriptions of how to do "bare" (no build system) C and C++ builds - just to show where things should go. * Apply suggestions from code review Co-authored-by: Mosè Giordano <765740+giordano@users.noreply.github.com> --------- Co-authored-by: Mosè Giordano <765740+giordano@users.noreply.github.com>
1 parent aa0df0e commit 4807e56

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/src/build_tips.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,36 @@ Example of packages using Rust:
127127

128128
The Rust toolchain currently used does not work with the `i686-w64-mingw32` (32-bit Windows) platform.
129129

130+
## C builds
131+
132+
If your library has no build system like Make, CMake, Meson, or Autoconf, you may need to use the C compiler directly. The C compiler is stored in the `CC` environment variable, and you can direct output to `libdir` (shared libraries) and `bindir` (executables).
133+
As a high-level example:
134+
135+
```sh
136+
# this assumes you are operating out of a Git source named `hello`
137+
# adjust your `cd` appropriately
138+
cd $WORKSPACE/srcdir/hello
139+
mkdir -p ${libdir} # make sure the libdir is instantiated
140+
${CC} -shared -o ${libdir}/libhello.${dlext} -fPIC hello.c # compile the library, save to `libdir`
141+
```
142+
143+
This is simply compiling a single shared library, `libhello`, from `hello.c`.
144+
145+
## C++ builds
146+
147+
Similarly to C builds, sometimes your C++ libraries will not have a build system associated with them. The C++ compiler is stored in the `CXX` environment variable.
148+
As a high-level example:
149+
150+
```sh
151+
# this assumes you are operating out of a Git source named `hello`
152+
# adjust your `cd` appropriately
153+
cd $WORKSPACE/srcdir/hello
154+
mkdir -p ${libdir}
155+
$CXX -shared -std=c++11 -O3 -fPIC -o ${libdir}/libhello.${dlext} src/hello.cpp # you may want to edit the `std` flag, for example
156+
```
157+
158+
This is simply compiling a single shared library, `libhello`, from `hello.cpp`.
159+
130160
## Editing files in the wizard
131161

132162
In the wizard, the `vim` editor is available for editing files. But, it doesn't leave any record in the build script. One generally needs to provide patch files or use something like `sed`. If a file needs patching, we suggest using `git` to add the entire worktree to a new repo, make the changes you need, then use `git diff -p` to output a patch that can be included alongside your build recipe.

0 commit comments

Comments
 (0)