Last active
March 27, 2025 14:53
-
-
Save StanleyGoldman/046e9cddad3e0c90c6d082749fdb1db0 to your computer and use it in GitHub Desktop.
Using swig_add_library in cmake
This file contains hidden or 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
cmake_minimum_required(VERSION 3.21) | |
project(codebase_wrapper LANGUAGES CXX) | |
find_package(SWIG REQUIRED) | |
include(${SWIG_USE_FILE}) | |
include_directories(${CMAKE_SOURCE_DIR}) | |
set(SOURCES codebase_wrapper.i codebase.c) | |
set_property(SOURCE codebase_wrapper.i PROPERTY CPLUSPLUS ON) | |
swig_add_library(${PROJECT_NAME} | |
TYPE SHARED | |
LANGUAGE csharp | |
OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Generated" | |
OUTFILE_DIR "${CMAKE_CURRENT_BINARY_DIR}/Wrapper" | |
SOURCES ${SOURCES} | |
) |
This file contains hidden or 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
#include "codebase.h" | |
#include <stdlib.h> | |
#include <string.h> | |
__declspec(dllexport) void helloWorld() | |
{ | |
} |
This file contains hidden or 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
// codebase.h | |
#ifndef CODEBASE_H | |
#define CODEBASE_H | |
__declspec(dllexport) typedef struct { | |
int id; | |
} DataStruct; | |
__declspec(dllexport) void helloWorld(); | |
#endif // CODEBASE_H |
This file contains hidden or 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
%module codebase_wrapper | |
%{ | |
#include "codebase.h" | |
%} | |
%include <windows.i> | |
%include "codebase.h" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Software Details
Running this example
Problem in build\codebase_wrapper.vcxproj
codebase.c
is included incodebase_wrapper.vcxproj
as None. Everything works if I were to manually change it to CLCompile.