I’ve been building a plugin for the Processing 4 IDE called C++ Mode. It lets you write sketches in C++, using the same API you’re used to. setup(), draw(), background(), mouseX, fill(), all still there.
C++ is rough to start with if you just want to draw something on screen. You need a build system, a window, an OpenGL context, and a pile of setup code before anything shows up. C++ Mode handles that part. Type this:
ellipse(300, 300, 50, 50);
Hit Run, see a circle.
If you already know Processing, you already know how to use this. Start with sketches that look like the Java version, then bring in structs, vectors, pointers, templates, whenever you want.
Its been quite awhile since I did any C++ programming so I was interested in trying it so I started with this on
Processing 4.5.6
iMac Intel processor
osx 15.7.6
// Full C++ STL is available without any #include.
// See https://processing-cpp.github.io/libraries
// Full C++ STL is available without any #include.
// See https://processing-cpp.github.io/libraries
void setup() {
// put your setup code here, to run once:
size(640, 360);
}
void draw() {
background(20);
ellipse(mouseX, mouseY, 40,40);
}
and got the following output, not sure if I missed doing something I should have
In file included from /Users/peter/Documents/Processing 3/modes/CppMode/src/Processing.cpp:48:
/Users/peter/Documents/Processing 3/modes/CppMode/src/stb_image_write.h:776:13: warning: 'sprintf' is deprecated: This
function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3),
it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]
776 | len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
| ^
/Applications/Programming/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_
stdio.h:278:1: note: 'sprintf' has been explicitly marked deprecated here
278 | __deprecated_msg("This function is provided for compatibility reasons only. Due to security concerns inherent
in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
| ^
/Applications/Programming/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/s
ys/cdefs.h:227:48: note: expanded from macro '__deprecated_msg'
227 | #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
| ^
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing.cpp:2213:27: warning: result of comparison of constant
128 with expression of type 'char' is always false [-Wtautological-constant-out-of-range-compare]
2213 | if (ch < 32 || ch >= 128) continue;
| ~~ ^ ~~~
2 warnings generated.
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:103:24: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
103 | inline void text(const std::string& s,float x,float y) { if(::g_papplet) ::g_papplet->text(s,x,y); }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:109:30: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
109 | inline float textWidth(const std::string& s) { return ::g_papplet ? ::g_papplet->textWidth(s) : 0; }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:112:24: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
112 | inline void save(const std::string& f="") { if(::g_papplet) ::g_papplet->save(f); }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:112:37: error: reference to type 'const int'
could not bind to an lvalue of type 'const char[1]'
112 | inline void save(const std::string& f="") { if(::g_papplet) ::g_papplet->save(f); }
| ^ ~~
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:112:37: note: passing argument to parameter 'f'
here
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:113:29: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
113 | inline void saveFrame(const std::string& f="frame-####.png"){ if(::g_papplet) ::g_papplet->saveFrame(f); }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:113:42: error: reference to type 'const int'
could not bind to an lvalue of type 'const char[15]'
113 | inline void saveFrame(const std::string& f="frame-####.png"){ if(::g_papplet) ::g_papplet->saveFrame(f); }
| ^ ~~~~~~~~~~~~~~~~
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:113:42: note: passing argument to parameter 'f'
here
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:114:32: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
114 | inline PImage* loadImage(const std::string& p) { return ::g_papplet ? ::g_papplet->loadImage(p) :
nullptr; }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:162:31: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
162 | inline void windowTitle(const std::string& t) { if(::g_papplet) ::g_papplet->windowTitle(t); }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:163:29: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
163 | inline PFont loadFont(const std::string& f) { static PFont d; return ::g_papplet ?
::g_papplet->loadFont(f) : d; }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
9 errors generated.
I ran the following source code per the instructions and got an error message similar to Quark. I also had to use Homebrew to install ‘glew’ and also updated ‘glfw’ initially.
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:1:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing.h:378:48: warning: implicit conversion from 'int' to
'float' changes value from 2147483647 to 2147483648 [-Wimplicit-const-int-float-conversion]
378 | float a = static_cast(rand()) / RAND_MAX * 6.28318f;
| ~ ^~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdlib.h:124
:18: note: expanded from macro 'RAND_MAX'
124 | #define RAND_MAX 0x7fffffff
| ^~~~~~~~~~
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:1:
/Users/xxxx/Documents/Processing/modes/CppMode/src/Processing.h:382:48: warning: implicit conversion from 'int' to
'float' changes value from 2147483647 to 2147483648 [-Wimplicit-const-int-float-conversion]
382 | float t = static_cast(rand()) / RAND_MAX * 6.28318f;
| ~ ^~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdlib.h:124
:18: note: expanded from macro 'RAND_MAX'
124 | #define RAND_MAX 0x7fffffff
| ^~~~~~~~~~
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:1:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing.h:383:67: warning: implicit conversion from 'int' to
'float' changes value from 2147483647 to 2147483648 [-Wimplicit-const-int-float-conversion]
383 | float p = ::std::acos(2.0f * static_cast(rand()) / RAND_MAX - 1.0f);
| ~ ^~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdlib.h:124
:18: note: expanded from macro 'RAND_MAX'
124 | #define RAND_MAX 0x7fffffff
| ^~~~~~~~~~
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:103:24: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
103 | inline void text(const std::string& s,float x,float y) { if(::g_papplet) ::g_papplet->text(s,x,y); }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:109:30: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
109 | inline float textWidth(const std::string& s) { return ::g_papplet ? ::g_papplet->textWidth(s) : 0; }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:112:24: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
112 | inline void save(const std::string& f="") { if(::g_papplet) ::g_papplet->save(f); }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:112:37: error: reference to type 'const int' could
not bind to an lvalue of type 'const char[1]'
112 | inline void save(const std::string& f="") { if(::g_papplet) ::g_papplet->save(f); }
| ^ ~~
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:112:37: note: passing argument to parameter 'f'
here
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:113:29: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
113 | inline void saveFrame(const std::string& f="frame-####.png"){ if(::g_papplet) ::g_papplet->saveFrame(f); }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:113:42: error: reference to type 'const int' could
not bind to an lvalue of type 'const char[15]'
113 | inline void saveFrame(const std::string& f="frame-####.png"){ if(::g_papplet) ::g_papplet->saveFrame(f); }
| ^ ~~~~~~~~~~~~~~~~
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:113:42: note: passing argument to parameter 'f'
here
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:114:32: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
114 | inline PImage* loadImage(const std::string& p) { return ::g_papplet ? ::g_papplet->loadImage(p) :
nullptr; }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:162:31: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
162 | inline void windowTitle(const std::string& t) { if(::g_papplet) ::g_papplet->windowTitle(t); }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:163:29: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
163 | inline PFont loadFont(const std::string& f) { static PFont d; return ::g_papplet ?
::g_papplet->loadFont(f) : d; }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
3 warnings and 9 errors generated.
Hi quark and svan! Both of these are fixed in v0.5.0 which just came out. The std::string error on Apple clang and the sprintf warning are both gone, and you no longer need to manually install glfw/glew via Homebrew since the dylibs are now bundled. Let me know how it goes!
There is no output on the screen other than this data. I tried to run the same source code listed above. I’m a little surprised at ‘g++’; I would expect ‘clang’ but maybe it makes no difference?
I tried the example again with 0.5.2 and got 9 errors a/l basically complaining about the same thing using std
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_13373917574561512436temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:104:24: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
104 | inline void text(const std::string& s,float x,float y) { if(::g_papplet) ::g_papplet->text(s,x,y); }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_13373917574561512436temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_13373917574561512436temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:110:30: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
110 | inline float textWidth(const std::string& s) { return ::g_papplet ? ::g_papplet->textWidth(s) : 0; }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_13373917574561512436temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_13373917574561512436temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:113:24: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
113 | inline void save(const std::string& f="") { if(::g_papplet) ::g_papplet->save(f); }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_13373917574561512436temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_13373917574561512436temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:113:37: error: reference to type 'const int'
could not bind to an lvalue of type 'const char[1]'
113 | inline void save(const std::string& f="") { if(::g_papplet) ::g_papplet->save(f); }
| ^ ~~
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:113:37: note: passing argument to parameter 'f'
here
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:114:29: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
114 | inline void saveFrame(const std::string& f="frame-####.png"){ if(::g_papplet) ::g_papplet->saveFrame(f); }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_13373917574561512436temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_13373917574561512436temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:114:42: error: reference to type 'const int'
could not bind to an lvalue of type 'const char[15]'
114 | inline void saveFrame(const std::string& f="frame-####.png"){ if(::g_papplet) ::g_papplet->saveFrame(f); }
| ^ ~~~~~~~~~~~~~~~~
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:114:42: note: passing argument to parameter 'f'
here
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:115:32: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
115 | inline PImage* loadImage(const std::string& p) { return ::g_papplet ? ::g_papplet->loadImage(p) :
nullptr; }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_13373917574561512436temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_13373917574561512436temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:163:31: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
163 | inline void windowTitle(const std::string& t) { if(::g_papplet) ::g_papplet->windowTitle(t); }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_13373917574561512436temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_13373917574561512436temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:164:29: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
164 | inline PFont loadFont(const std::string& f) { static PFont d; return ::g_papplet ?
::g_papplet->loadFont(f) : d; }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_13373917574561512436temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
9 errors generated.
Hey quark! The fix is in there but you need to delete the whole CppMode folder from Documents/Processing/modes/ and reinstall fresh, not just the jar. The src/ folder inside it needs to be replaced too and that’s where the fix actually lives. Let me know how it goes!
Hey svan! Just pushed v0.5.3 with a fix for the window not showing up. The engine now registers with the macOS window server before GLFW starts which is needed when it gets launched as a subprocess from the IDE. Would love to know if that sorts it out for you!
I updated C++ mode to 0.5.3 by using the Contribution Manager and then tried to run the source code I initially posted. Got these error messages:
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo948270829610532781temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:104:24: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
104 | inline void text(const std::string& s,float x,float y) { if(::g_papplet) ::g_papplet->text(s,x,y); }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo948270829610532781temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from /var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo948270829610532781temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:110:30: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
110 | inline float textWidth(const std::string& s) { return ::g_papplet ? ::g_papplet->textWidth(s) : 0; }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo948270829610532781temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from /var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo948270829610532781temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:113:24: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
113 | inline void save(const std::string& f="") { if(::g_papplet) ::g_papplet->save(f); }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo948270829610532781temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from /var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo948270829610532781temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:113:37: error: reference to type 'const int' could not bind to an lvalue of type 'const char[1]'
113 | inline void save(const std::string& f="") { if(::g_papplet) ::g_papplet->save(f); }
| ^ ~~
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:113:37: note: passing argument to parameter 'f' here
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:114:29: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
114 | inline void saveFrame(const std::string& f="frame-####.png"){ if(::g_papplet) ::g_papplet->saveFrame(f); }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo948270829610532781temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from /var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo948270829610532781temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:114:42: error: reference to type 'const int' could not bind to an lvalue of type 'const char[15]'
114 | inline void saveFrame(const std::string& f="frame-####.png"){ if(::g_papplet) ::g_papplet->saveFrame(f); }
| ^ ~~~~~~~~~~~~~~~~
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:114:42: note: passing argument to parameter 'f' here
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:115:32: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
115 | inline PImage* loadImage(const std::string& p) { return ::g_papplet ? ::g_papplet->loadImage(p) :
nullptr; }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo948270829610532781temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from /var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo948270829610532781temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:163:31: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
163 | inline void windowTitle(const std::string& t) { if(::g_papplet) ::g_papplet->windowTitle(t); }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo948270829610532781temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from /var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo948270829610532781temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:164:29: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
164 | inline PFont loadFont(const std::string& f) { static PFont d; return ::g_papplet ?
::g_papplet->loadFont(f) : d; }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo948270829610532781temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
9 errors generated.
I deleted the whole CppMode folder and installed 0.5.3 from scratch using the contributions manager
I closed and restarted Processing and tried the example again and I got the following errors which appear to be the same as my last post.
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_112022778545587407135temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:104:24: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
104 | inline void text(const std::string& s,float x,float y) { if(::g_papplet) ::g_papplet->text(s,x,y); }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_112022778545587407135temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_112022778545587407135temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:110:30: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
110 | inline float textWidth(const std::string& s) { return ::g_papplet ? ::g_papplet->textWidth(s) : 0; }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_112022778545587407135temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_112022778545587407135temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:113:24: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
113 | inline void save(const std::string& f="") { if(::g_papplet) ::g_papplet->save(f); }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_112022778545587407135temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_112022778545587407135temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:113:37: error: reference to type 'const int'
could not bind to an lvalue of type 'const char[1]'
113 | inline void save(const std::string& f="") { if(::g_papplet) ::g_papplet->save(f); }
| ^ ~~
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:113:37: note: passing argument to parameter 'f'
here
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:114:29: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
114 | inline void saveFrame(const std::string& f="frame-####.png"){ if(::g_papplet) ::g_papplet->saveFrame(f); }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_112022778545587407135temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_112022778545587407135temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:114:42: error: reference to type 'const int'
could not bind to an lvalue of type 'const char[15]'
114 | inline void saveFrame(const std::string& f="frame-####.png"){ if(::g_papplet) ::g_papplet->saveFrame(f); }
| ^ ~~~~~~~~~~~~~~~~
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:114:42: note: passing argument to parameter 'f'
here
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:115:32: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
115 | inline PImage* loadImage(const std::string& p) { return ::g_papplet ? ::g_papplet->loadImage(p) :
nullptr; }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_112022778545587407135temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_112022778545587407135temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:163:31: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
163 | inline void windowTitle(const std::string& t) { if(::g_papplet) ::g_papplet->windowTitle(t); }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_112022778545587407135temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_112022778545587407135temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:164:29: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
164 | inline PFont loadFont(const std::string& f) { static PFont d; return ::g_papplet ?
::g_papplet->loadFont(f) : d; }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_112022778545587407135temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
9 errors generated.
Really appreciate you both sticking with this and continuing to report back, it genuinely means a lot and is making the mode way better.
Just pushed v0.5.4 which should fix the std::string errors for good. I rebuilt the cache from scratch which seems to have been the underlying cause. For svan, the window not showing up on macOS is also addressed in this release. Give it a try and let me know how it goes!
Contribution Manager shows that this version is already installed. I downloaded it again and put CppMode folder in Documents/Processing/modes, replacing the folder that was already there. Ran the same demo as before and got this output:
ld: library 'glfw' not found clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Tried to reinstall ‘glfw’ with ‘brew’; terminal output says it’s already installed. Not sure what else to try.
Just pushed v0.6.0 which should fix the ld: library 'glfw' not found error. The bundled macOS libraries now include the unversioned libglfw.dylib that the linker needs, so it no longer depends on Homebrew being set up in any particular way.
Reason: tried: ‘/libglfw.3.dylib’ (no such file), ‘/Applications/Processing.app/Contents/app/libglfw.3.dylib’ (no such file), ‘/Users/xxxxx/Documents/Processing/modes/CppMode/libs/macos/libglfw.3.dylib’ (code signature in ‘/Users/xxxxx/Documents/Processing/modes/CppMode/libs/macos/libglfw.3.dylib’ not valid for use in process: library load disallowed by system policy), ‘/System/Volumes/Preboot/Cryptexes/OS/Users/xxxxx/Documents/Processing/modes/CppMode/libs/macos/libglfw.3.dylib’ (no such file), ‘/private/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/sketch_260823b16282415172506251136temp/libglfw.3.dylib’ (code signature in ‘/private/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/sketch_260823b16282415172506251136temp/libglfw.3.dylib’ not valid for use in process: library load disallowed by system policy), ‘/Users/xxxxx/Documents/Processing/modes/CppMode/libs/macos/libglfw.3.dylib’ (code signature in ‘/Users/xxxxx/Documents/Processing/modes/CppMode/libs/macos/libglfw.3.dylib’ not valid for use in process: library load disallowed by system policy), ‘/System/Volumes/Preboot/Cryptexes/OS/Users/xxxxx/Documents/Processing/modes/CppMode/libs/macos/libglfw.3.dylib’ (no such file), ‘/private/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/sketch_260823b16282415172506251136temp/libglfw.3.dylib’ (code signature in ‘/private/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/sketch_260823b16282415172506251136temp/libglfw.3.dylib’ not valid for use in process: library load disallowed by system policy)
Addendum - Good news:
I took the CppMode/libs/macos folder which contains the above library out of quarantine by using an ‘xattr’ utility written for this purpose and it worked! I can now run the demo cited above:
Looks like a code signing issue and getting around Apple’s gatekeeper. At least there is a workaround. I did not try ‘xattr’ from the Terminal command line but it would possibly work also.
Really glad it’s working for you quark! And thanks svan for tracking down the xattr fix yourself, that’s exactly what v0.6.1 does automatically now. The mode strips the quarantine attribute from the bundled libraries before compiling, so you won’t need to do it manually anymore.