danomatika / ofxPd

(maintained) a Pure Data addon for OpenFrameworks using libpd
Other
202 stars 45 forks source link

error compiling pdMultiExample with PDINSTANCE and PDTHREADS #81

Closed Ant1r closed 3 years ago

Ant1r commented 3 years ago

I have a strange error while trying to make pdMultiExample after defining PDINSTANCE and PDTHREADS from the config.make file: PROJECT_CFLAGS = -DHAVE_UNISTD_H -DUSEAPI_DUMMY -DPD -DLIBPD_EXTRA -DLIBPD_USE_STD_MUTEX -DPDINSTANCE -DPDTHREADS

the compiler complains:

In file included from /home/arsene/Documents/OF/of_v0.9.8_linux64_release/addons/ofxPd/libs/libpd/libpd_wrapper/z_libpd.h:21:0,
                 from /home/arsene/Documents/OF/of_v0.9.8_linux64_release/addons/ofxPd/libs/libpd/cpp/PdBase.hpp:16,
                 from ../../../addons/ofxPd/src/ofxPd.h:21,
                 from ../../../addons/ofxPd/src/ofxPd.cpp:16:
/usr/include/boost/io/detail/quoted_manip.hpp: At global scope:
/home/arsene/Documents/OF/of_v0.9.8_linux64_release/addons/ofxPd/libs/libpd/pure-data/src/m_pd.h:895:29: error: expected ‘)’ before ‘->’ token
 #define s_          (pd_this->pd_s_)
                             ^
/home/arsene/Documents/OF/of_v0.9.8_linux64_release/addons/ofxPd/libs/libpd/pure-data/src/m_pd.h:895:29: error: expected ‘)’ before ‘->’ token
/home/arsene/Documents/OF/of_v0.9.8_linux64_release/addons/ofxPd/libs/libpd/pure-data/src/m_pd.h:895:31: error: ‘pd_s_’ does not name a type
 #define s_          (pd_this->pd_s_)
                               ^
/home/arsene/Documents/OF/of_v0.9.8_linux64_release/addons/ofxPd/libs/libpd/pure-data/src/m_pd.h:895:31: error: ‘quoted_proxy’ function with trailing return type not declared with ‘auto’ type specifier
/home/arsene/Documents/OF/of_v0.9.8_linux64_release/addons/ofxPd/libs/libpd/pure-data/src/m_pd.h:895:31: error: expected ‘;’ at end of member declaration
/home/arsene/Documents/OF/of_v0.9.8_linux64_release/addons/ofxPd/libs/libpd/pure-data/src/m_pd.h:895:36: error: expected unqualified-id before ‘)’ token
 #define s_          (pd_this->pd_s_)

It seems that the error is only triggered for the s_ symbol definition: if I comment this line out, ofxPd.cc compiles fine (obviously some of puredata source files cannot compile anymore). BTW I successfully compiled libpd/samples/c/pdtest_multi, which also defines of PDINSTANCE and PDTHREADS. So it could be related to compiling with g++ instead of gcc.

Any idea?

danomatika commented 3 years ago

So it could be related to compiling with g++ instead of gcc.

I don't know if that's the problem, but I think you should build the C files with gcc, yes.

danomatika commented 3 years ago

I am also updating this to pd 0.51-3 when it is finalized, although the multi instance support is not quite working well due to a number of reasons. The multi example here doesn't run very well.

Ant1r commented 3 years ago

OK, I'm starting to understand. In the file usr/include/boost/io/detail/quoted_manip.hpp, the name "_s" is used once in a function declaration:

quoted_proxy(String s_, Char escape_, Char delim_) : string(s_), escape(escape_), delim(delim_) {}

But since "_s" is replaced with "(pd_this->pd_s_)" by m_pd.h, the compiler throws an error while parsing quoted_manip.hpp.

So currently PDINSTANCE is incompatible with compiling with boost... The problem is OF doesn't allow to selectively choose the compiler.

danomatika commented 3 years ago

Build libpd separately and link the .a. I just merged a PR which adds a STATIC=true makefile option and poops out a libpd.a into the libs directory.

Ant1r commented 3 years ago

OK I found a fix!

in the top of ofxPd.cpp, add #include "ofMain.h" before #include "ofxPd.h"

This way, OF stuff (including boost one) is parsed before m_pd.h can polute the namespace, and the error disappears!

danomatika commented 3 years ago

Oophh. ofMain.h is huge and I try not to bring it in when I can. Can you try ofConstants.h first?

Ant1r commented 3 years ago

Adding ofConstants.h doesn't work.

The smallest possible OF file is ofFileUtils.h, because it's the only one that includes boost/filesystem.hpp, which in turn calls boost/filesystem/path.hpp, which calls boost/io/detail/quoted_manip.hpp...

IMO including ofFileUtils.h seems a bit obscure, while ofMain.h is simpler to understand; and it's only impacting ofxPd.cpp compilation. But I'd be fine with ofFileUtils.h if you prefer. It would fix my problem anyway.

danomatika commented 3 years ago

I'd prefer ofFileUtils.h. Should be fixed with f8728c5 I mean 0935775

Ant1r commented 3 years ago

thanks!