> crystal test.cr
Undefined symbols for architecture x86_64:
"std::string::_Rep::_M_destroy(std::allocator<char> const&)", referenced from:
Hello::hello(char const*) in hello.a(libhello.o)
"std::string::_Rep::_S_empty_rep_storage", referenced from:
Hello::hello(char const*) in hello.a(libhello.o)
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
Hello::hello(char const*) in hello.a(libhello.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with code: 1: `cc -o "/Users/laurynas/.cache/crystal/crystal-run-test.tmp" "${@}" -rdynamic /Users/laurynas/temp/test_crystal/build/Release/hello.a -lstdc++ -lpcre -lgc -lpthread /usr/local/Cellar/crystal-lang/0.19.4/src/ext/libcrystal.a -levent -liconv -ldl -L/usr/lib -L/usr/local/lib`
test.cr
require "./lib_hello"
LibHello.hello("Bob")
lib_hello.cr
@[Link("stdc++", ldflags: "/Users/laurynas/temp/test_crystal/build/Release/hello.a")]
lib LibHello
fun hello = hello_wrapper(name : UInt8*)
end
libhello_wrapper.cpp
#include "libhello.h"
extern "C" {
void hello_wrapper(const char* name) {
Hello::hello(name);
}
}
libhello.cpp
#include <stdio.h>
#include <string>
namespace Hello {
void hello(const char* name) {
std::string test(name);
printf("Hello %s.\n", test.c_str());
}
}