Group Abstract Group Abstract

Message Boards Message Boards

0
|
11.6K Views
|
11 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Issues with WSTP

Posted 9 years ago

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.

Thanks, Francesco

11 Replies
POSTED BY: Ilian Gachevski

I included -stdlib=libstdc++ but it didn't seem to work. How did you compile the file?

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 $@
POSTED BY: Ilian Gachevski
Posted 9 years ago
POSTED BY: Shujie CHEN

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

Do both -stdlib=libstdc++ and -lstdc++ appear on your linker command line?

POSTED BY: Ilian Gachevski

I just made that adjustment and get an error that starts like this:

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)
      ...

It may be the same exact one I had earlier

Prior to version 10.4, use -lstdc++ in EXTRA_LIBS to link against libstdc++ instead of libc++

(there is also an alternative set of WSTP libraries supplied if you wish to use the libc++ standard library instead).

POSTED BY: Ilian Gachevski

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);
}

f.tm

:Begin:
:Function:      f
:Pattern:       f[x_Integer, y_Integer]
:Arguments:     {x, y}
:ArgumentTypes: {Integer, Integer}
:ReturnType:    Integer
:End:

make

# 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 $@

Are you on OS X? Which version of Mathematica are you using?

You may need -stdlib=libstdc++ but that's difficult to say without the above information and the actual Makefile.

POSTED BY: Ilian Gachevski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard