Use of existing C++ libraries (like wxWidget or other C or Objective-C libraries) #26
Replies: 6 comments 7 replies
-
In theory, it is possible to use existing libraries. However, it is often a valid statement that it is not possible to do this directly. As can be seen in the C++ interoperability documentation, a binding is required. But if the types are compatible, only binding is sufficient. You don't need to do anything additional in any way. In addition, Jule does not have all the design elements of C++. The most common situation that can cause problems when using an external library is when the external library requires a namespace. Therefore, you may need to write a custom binding header file for Jule and define functions that allow you to avoid namespaces. For example: jule::Int get_magic_number() {
return mylibrary::get_magic_number();
} The code above is a binding-compatible C++ function wrapper for the As for what kind of bindings Jule supports, the C++ interoperability documentation mentions all types of bindings. Anything other than these is not supported. If you need a wrapper feel free to make it, you probably won't have a problem. However, if you want to create a fully compatible Jule binding of a 3rd party C++ library, you may need to spend some time doing this, but it will probably take much less time than writing the entire library in Jule. |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for your thorough explanation. |
Beta Was this translation helpful? Give feedback.
-
From the interoperability documentation: // sum.hpp
using namespace jule;
Int sum(const Slice slice) {
Int total{ 0 };
for (const Int x: slice)
total += x;
return total;
} // main.jule
use cpp "sum.hpp"
cpp fn sum([]int): int
fn main() {
let numbers = [1, 2, 3, 4, 5, 6, 7, 8]
let total = cpp.sum(numbers)
outln(total)
} does not compile, and the only message is: Using clang separate I get the following error message:
Would be nice if juleC would show clang's error messages. |
Beta Was this translation helpful? Give feedback.
-
Yes, this was it. Thank you. |
Beta Was this translation helpful? Give feedback.
-
Adding normal Using Digging through the internet revealed that As I'm no Here the #import <stdlib.h>
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
// the include file just defines the functions in this file
#include "import_extern_obj-c.h"
void Export_Function() {
printf("Hello from Objective-C!\n");
}
int GetBitsPerPixel(int index) {
NSScreen *screen = [NSScreen mainScreen];
NSWindowDepth depth = [screen depth];
return (int) NSBitsPerPixelFromDepth (depth);
} I did the same test with the |
Beta Was this translation helpful? Give feedback.
-
Using your code worked, which is awesome! Looking at the differences to what I did: Using Changing the file extension from Thank you so much for helping me out. The only thing that is left to do (on your side :D ) is to add something to add the Again, thank you so much for helping me out. This is so awesome! EDIT: |
Beta Was this translation helpful? Give feedback.
-
Do I need to create C++ 'glue code' for existing C++ libraries (like wxWidget) or can I use them with normal Jule code?
Any hints how to use existing C++ (or C or Objective-C) libraries are welcome.
Thank you in advance.
Beta Was this translation helpful? Give feedback.
All reactions