Hello,
I’m trying to do some fairly simple stuff with WSTP, creating a function ‘f’ which returns the sum of the two arguments.
I followed the instruction for making the template files and make file, but I get a long error message.
This is the start of it the error:
Undefined symbols for architecture x86_64:
"std::__basic_file<char>::is_open() const", referenced from:
WSTP::MLLog::logSelectorToFileWithName(WSTP::mllogselector, char const*) in libWSTPi4.a(mllog.cpp.o)
"std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::str() const", referenced from:
mlopen_argv(ws_environment*, long, char**, void*, void*, int*) in libWSTPi4.a(mlopen.c.o)
WSTP::MLLog::~MLLog() in libWSTPi4.a(mllog.cpp.o)
"std::basic_ios<char, std::char_traits<char> >::widen(char) const", referenced from:
feature_greeting(ws_environment*, WSLink*, device_kebab*, _queue*, feature_set*) in libWSTPi4.a(mlgreet.c.o)
WSTP::MLExceptionMessage::print(std::ostream&) const in libWSTPi4.a(mlexceptions.cpp.o)
WSTP::initSyncObjectDir() in libWSTPi4.a(mlplatformthreads.cpp.o)
WSTP::MLLog::~MLLog() in libWSTPi4.a(mllog.cpp.o)
WSTP::MLLog::operator()(WSTP::mllogselector) in libWSTPi4.a(mllog.cpp.o)
WSTP::MLExprLog::writeContentsToStreams(WSTP::MLExprLog::mllogdirection&, bool, std::basic_ostringstream<char, std::char_traits<char>, WSTP::MLStdAllocator<char> >&) in libWSTPi4.a(mlexprlog.cpp.o)
WSTP::MLInterfaceContainer::PrintInterfaceContainer(std::ostream&) const in libWSTPi4.a(mlinterface.cpp.o)
...
If anyone has any idea how to solve the problem, please contact me. I can provide the template and make files used too.
I am using OS X (10.11.5) with Mathematica 10.
I’m attaching the make file and template files. The files cannot be attached, so I just pasted their content in here.
f.c
#include <stdio.h>
#include <stdlib.h>
#include "wstp.h"
extern int f( int i, int j);
int f(int x, int y) {
return x+y;
}
int main(int argc, char *argv[]) {
return WSMain(argc, argv);
}
# This makefile can be used to build all or some of the sample
# programs. To build all of them, use the command
# 'make all'. To build one, say addtwo, use the command
# 'make addtwo'.
WSLINKDIR = /Applications/Mathematica.app/Contents/SystemFiles/Links/WSTP/DeveloperKit
SYS = MacOSX-x86-64
CADDSDIR = ${WSLINKDIR}/${SYS}/CompilerAdditions
INCDIR = ${CADDSDIR}
LIBDIR = ${CADDSDIR}
WSPREP = ${CADDSDIR}/wsprep
EXTRA_CFLAGS=-stdlib=libstdc++
EXTRA_LIBS = -lc++ -framework Foundation
MATHLINK_LIB = -lWSTPi4
all : f
f : ftm.o f.o
${CC} -I${INCDIR} ftm.o f.o -L${LIBDIR} ${MATHLINK_LIB} ${EXTRA_LIBS} -o $@
.c.o :
${CC} -c ${EXTRA_CFLAGS} -I${INCDIR} $<
ftm.c : f.tm
${WSPREP} $? -o $@
Right now my make file is giving the following error:
Undefined symbols for architecture x86_64:
"_WSMain", referenced from:
_main in f.o
ld: symbol(s) not found for architecture x86_64
So I’ve been compiling executing the different commands in the make file. The -stdlib=libstdc++ is the EXTRA_CFLAGS which appears only in the second command. The error I showed earlier comes from the first command:
cc -I/Applications/Mathematica.app/Contents/SystemFiles/Links/WSTP/DeveloperKit/MacOSX-x86-64/CompilerAdditions ftm.o f.o -L/Applications/Mathematica.app/Contents/SystemFiles/Links/WSTP/DeveloperKit/MacOSX-x86-64/CompilerAdditions -lWSTPi4 -ls tdc++ -framework Foundation -o f
I think I already mentioned this but just in case: -stdlib=libstdc++ is also needed when you call the linker.
This is your code compiling without errors on my Mac using Mathematica 10.0.
/Applications/M.app/SystemFiles/Links/WSTP/DeveloperKit/MacOSX-x86-64/CompilerAdditions/wsprep f.tm -o ftm.c
cc -c -stdlib=libstdc++ -I/Applications/M.app/SystemFiles/Links/WSTP/DeveloperKit/MacOSX-x86-64/CompilerAdditions ftm.c
cc -c -stdlib=libstdc++ -I/Applications/M.app/SystemFiles/Links/WSTP/DeveloperKit/MacOSX-x86-64/CompilerAdditions f.c
cc -stdlib=libstdc++ -I/Applications/M.app/SystemFiles/Links/WSTP/DeveloperKit/MacOSX-x86-64/CompilerAdditions ftm.o f.o -L/Applications/M.app/SystemFiles/Links/WSTP/DeveloperKit/MacOSX-x86-64/CompilerAdditions -lWSTPi4 -lstdc++ -framework Foundation -o f
clang: warning: libstdc++ is deprecated; move to libc++
where I changed the Makefile to contain
EXTRA_CFLAGS=-stdlib=libstdc++
EXTRA_LIBS = -lstdc++ -framework Foundation
MATHLINK_LIB = -lWSTPi4
all : f
f : ftm.o f.o
${CC} ${EXTRA_CFLAGS} -I${INCDIR} ftm.o f.o -L${LIBDIR} ${MATHLINK_LIB} ${EXTRA_LIBS} -o $@
By typing make but you can see the exact 4 commands it ran in my post. The contents of f.c and f.tm were taken from above.
Another thing you may want to check is the exact path to WSTP on your system, in particular whether it has Contents/SystemFiles/Links in it or just SystemFiles/Links (for me with version 10.0 it was the latter).