# Build C/C++ code on the fly

Build C/C++ code on the fly

## Description

Nelson provides a cross-platform command-line tool written in Nelson for compiling native addon modules for Nelson.

It takes away the pain of dealing with the various differences in build platforms.

## Example

```matlab
if ispc() && ~havecompiler()
configuremsvc()
end
C_CONTENT = ["double";
"functionC(double x)";
"{";
"    return x + 8;";
"}"];
DEST_DIR = [tempdir(), 'example_C'];
mkdir(DEST_DIR);
C_DEST_FILE = [tempdir(), 'example_C/demo.c'];
filewrite(C_DEST_FILE, C_CONTENT)

dlgeneratemake(DEST_DIR, 'C_DEMO', {C_DEST_FILE}, {DEST_DIR})
[res, message] = dlmake(DEST_DIR)

lib = dlopen([DEST_DIR, '/C_DEMO', getdynlibext()])
c = dllibinfo(lib)

f = dlsym(lib, 'functionC', 'double', {'double'});
R = dlcall(f, 3) % 8 + 3
dlclose(lib)
```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-584c0e6a591fd88fedfcace89aaf59362341e7b9%2Fbuild_c_cpp_on_fly_DE9671CD.png?alt=media)

## See also

[configuremsvc](configuremsvc), [dlgeneratemake](dlgeneratemake), [dlmake](dlmake), [dlopen](dlopen), [dllibinfo](dllibinfo), [dlsym](dlsym), [dlcall](dlcall).

## History

| Version | Description     |
| ------- | --------------- |
| 1.2.0   | initial version |

## Author

Allan CORNET
