title: Xcode C++ code in cocoa app about serial port get operation not permitted
body: <p>I build a code in <code>Xcode</code> console with <code>C++</code> project works perfectly before:</p>
  
  <p><img src="https://i.stack.imgur.com/LNVpV.jpg" alt="Photo"></p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "SerialPort.hpp"
  #include "TypeAbbreviations.hpp"
  #include &lt;iostream&gt;
  
  int main(int argc, const char * argv[]) {
  
      //* Open port, and connect to a device
      const char devicePathStr[] = "/dev/tty.usbserial-A104RXG4";
      const int baudRate = 9600;
      int sfd = openAndConfigureSerialPort(devicePathStr, baudRate);
      if (sfd &lt; 0) {
          if (sfd == -1) {
              printf("Unable to connect to serial port.\n");
          }
          else { //sfd == -2
              printf("Error setting serial port attributes.\n");
          }
          return 0;
      }
  
      // * Read using readSerialData(char* bytes, size_t length)
  
      // * Write using writeSerialData(const char* bytes, size_t length)
  
      // * Remember to flush potentially buffered data when necessary
  
      // * Close serial port when done
      const char dataToWrite[]="abcd";
      char databuffer[1024];
  
      while(1){
          readSerialData(databuffer, 4);
          sleep(2);
          writeSerialData(databuffer, 4);
          sleep(2);
  
      }
  
      printf("end.\n");
      return 0;
  }
  </code></pre>
  
  <p>After this build, I tried to migrate it to my <code>Xcode</code> cocoa application with <code>C++</code> wrappers below.</p>
  
  <p><img src="https://i.stack.imgur.com/NNOis.png" alt="Photo"></p>
  
  <p>I am pretty sure my <code>Wrapper</code> works fine with test <code>C++</code> code. That means, I can call <code>C++</code> function from my <code>ViewController.swift</code>.</p>
  
  <p>But there's one strange thing happened. I am not able to open connection with the following code:</p>
  
  <pre><code>    sfd = open(portPath, (O_RDWR | O_NOCTTY | O_NDELAY));
      if (sfd == -1) {
          printf("Unable to open serial port: %s at baud rate: %d\n", portPath, baudRate);
          printf("%s", std::strerror(errno));
          return sfd;
      }
  </code></pre>
  
  <p>There error message returns : </p>
  
  <pre><code>Unable to open serial port: /dev/tty.usbserial-A104RXG4 at baud rate: 9600
  Operation not permitted 
  </code></pre>
  
  <p>I've tried to change <code>app sandbox configuration</code>, set up my <code>system preference</code> to grant access to my <code>app</code>, also I disabled my <code>rootless</code>. (<code>csrutil</code> disable with <code>command + R</code>)
  But the problem still persists:</p>
  
  <p><img src="https://i.stack.imgur.com/rfD0e.png" alt="Problem"> &amp;
  <img src="https://i.stack.imgur.com/hwA6r.png" alt="Problem"></p>
  
  <p>I want to ask that:<br>
  1. Why my code on <code>Xcode C++</code> project works fine but fail on <code>swift's cocoa</code> app on <code>Xcode</code>?<br>
  2. How to solve the <code>"Operation not permitted"</code> Issue.</p>
  
  <p>My <code>Xcode</code> version is <code>11.3.1</code> and <code>Mac OS</code> is <code>10.14.6 Mojave</code>. </p>