Skip to content

Commit

Permalink
Fix realtime_example ffi resolution on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzybinary committed Feb 27, 2024
1 parent 7c88b6e commit 208d32a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
11 changes: 7 additions & 4 deletions examples/realtime_example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ cmake_minimum_required(VERSION 3.21)
project(realtime_example)
set(CMAKE_CXX_STANDARD 17)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

set(CUTE_FRAMEWORK_STATIC ON)
set(CF_FRAMEWORK_BUILD_TESTS OFF)
# Samples Build on Windows Falied
Expand All @@ -28,12 +26,17 @@ target_include_directories(realtime_example PRIVATE
"${DART_DIR}/runtime/include"
)

add_custom_target(ALWAYS_DO_POST_BUILD
if(LINUX)
# -export-dynamic is required on Linux if your symbols are in your executable,
# otherwise dlsym (and therefore Dart FFI) can't find them.
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -export-dynamic")
endif()

add_custom_command(TARGET realtime_example POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:realtime_example> $<TARGET_RUNTIME_DLLS:simple_example_ffi>
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/dart $<TARGET_FILE_DIR:realtime_example>/dart
COMMAND_EXPAND_LISTS
)
add_dependencies(realtime_example ALWAYS_DO_POST_BUILD)

target_link_libraries(realtime_example PUBLIC dart_dll cute)

Expand Down
15 changes: 3 additions & 12 deletions examples/realtime_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ bool init_dart() {
Dart_Handle result =
Dart_Invoke(root_library, init_function_name, 0, nullptr);
if (Dart_IsError(result)) {
std::cout << Dart_GetError(result);
Dart_ExitScope();
return false;
}
Expand Down Expand Up @@ -99,15 +100,9 @@ void render_drawables() {
// These need to be exposed as "C" functions and be exported
//
#if defined(_WIN32)
#define WORM_EXPORT __declspec(dllexport)
#elif defined(__GNUC__)
#define WORM_EXPORT __attribute__((visibility("default")))
#define WORM_EXPORT exten "C" __declspec(dllexport)
#else
#define WORM_EXPORT
#endif

#ifdef __cplusplus
extern "C" {
#define WORM_EXPORT extern "C" __attribute__((visibility("default"))) __attribute((used))
#endif

WORM_EXPORT unsigned int create_entity(int x, int y, int width, int height) {
Expand Down Expand Up @@ -140,10 +135,6 @@ WORM_EXPORT bool get_key_just_pressed(int key_code) {
return cf_key_just_pressed((CF_KeyButton)key_code);
}

#ifdef __cplusplus
}
#endif

int main(int argc, char* argv[]) {
// Create a window with a resolution of 640 x 480.
int options =
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_example_ffi/hello_world_ffi.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:ffi';
import 'package:ffi/ffi.dart';

@FfiNative<Void Function(Pointer<Utf8>)>("SimplePrint", isLeaf: true)
@Native<Void Function(Pointer<Utf8>)>(symbol: "SimplePrint", isLeaf: true)
external void simplePrint(Pointer<Utf8> string);

void main() {
Expand Down

0 comments on commit 208d32a

Please sign in to comment.