Interesting behaviour of preprocessor-command #define (regarding compilability) - c++

In an PlatformIO project I have a wrapper around this RFM69 library. The header file (named radio.h) contains the following:
#pragma once
#include <RFM69.h>
//struct for wireless data transmission
typedef struct {
...
} Payload;
class RFMRadio {
private:
RFM69* radio;
public:
RFMRadio();
~RFMRadio();
void Init();
void Send(int aDeviceID, float aValue);
void Sleep();
bool receiveDone(Payload& msg);
void listenModeStart();
void listenModeEnd();
};
In the project the listenMode of the RFM69 library is used (although it is buggy as the library itself states, unfortunately my superviser still wants to use those functions).
Natively this mode is not activated (line 174-184 of RFM69.h from the library linked above):
//Native hardware ListenMode is experimental
//It was determined to be buggy and unreliable, see https://lowpowerlab.com/forum/low-power-techniques/ultra-low-power-listening-mode-for-battery-nodes/msg20261/#msg20261
//uncomment to try ListenMode, adds ~1K to compiled size
//FYI - 10bit addressing is not supported in ListenMode
// #define RF69_LISTENMODE_ENABLE
#if defined(RF69_LISTENMODE_ENABLE)
// By default, receive for 256uS in listen mode and idle for ~1s
#define DEFAULT_LISTEN_RX_US 256
#define DEFAULT_LISTEN_IDLE_US 1000000
#endif
What I wanted to do is to write #define RF69_LISTENMODE_ENABLE in my radio.h file right before the #include <RFM69.h> statement like this:
#pragma once
#define RF69_LISTENMODE_ENABLE
#include <RFM69.h>
...
If I do this the code will not be compiled instead I get a lot of warnings like type 'struct RFM69' violates the C++ One Definition Rule [-Wodr] (Full errorlog at the bottom). However when I simply uncomment the // #define RF69_LISTENMODE_ENABLE line from the library code above the build runs without any problems. So with respect to the place where RF69_LISTENMODE_ENABLE is defined it is either possible to compile the code or not. I double checked if the RFM69-library is included elsewhere in the project an this is not the case.
I wonder what causes this behaviour?
Full error log:
.pio\libdeps\pro8MHzatmega328\RFM69/RFM69.h:186:7: warning: type 'struct RFM69' violates the C++ One Definition Rule [-Wodr]
class RFM69 {
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.h:186:7: note: a different type is defined in another translation unit
class RFM69 {
^
.pio\libdeps\pro8MHzatmega328\RFM69/RFM69.h:315:10: note: the first difference of corresponding definitions is field '_isHighSpeed'
bool _isHighSpeed;
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.h:186:7: note: a type with different number of fields is defined in another translation unit
class RFM69 {
^
.pio\libdeps\pro8MHzatmega328\RFM69/RFM69.h:212:10: warning: 'ACKRequested' violates the C++ One Definition Rule [-Wodr]
bool ACKRequested();
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:355:6: note: implicit this pointer type mismatch
bool RFM69::ACKRequested() {
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.h:186:7: note: type 'struct RFM69' itself violates the C++ One Definition Rule
class RFM69 {
^
.pio\libdeps\pro8MHzatmega328\RFM69/RFM69.h:186:7: note: the incompatible type is defined here
class RFM69 {
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:355:6: note: 'ACKRequested' was previously declared here
bool RFM69::ACKRequested() {
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:355:6: note: code may be misoptimized unless -fno-strict-aliasing is used
.pio\libdeps\pro8MHzatmega328\RFM69/RFM69.h:235:10: warning: 'writeReg' violates the C++ One Definition Rule [-Wodr]
void writeReg(uint8_t addr, uint8_t val);
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:546:6: note: implicit this pointer type mismatch
void RFM69::writeReg(uint8_t addr, uint8_t value)
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.h:186:7: note: type 'struct RFM69' itself violates the C++ One Definition Rule
class RFM69 {
^
.pio\libdeps\pro8MHzatmega328\RFM69/RFM69.h:186:7: note: the incompatible type is defined here
class RFM69 {
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:546:6: note: 'writeReg' was previously declared here
void RFM69::writeReg(uint8_t addr, uint8_t value)
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:546:6: note: code may be misoptimized unless -fno-strict-aliasing is used
.pio\libdeps\pro8MHzatmega328\RFM69/RFM69.h:203:10: warning: 'initialize' violates the C++ One Definition Rule [-Wodr]
bool initialize(uint8_t freqBand, uint16_t ID, uint8_t networkID=1);
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:60:6: note: implicit this pointer type mismatch
bool RFM69::initialize(uint8_t freqBand, uint16_t nodeID, uint8_t networkID)
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.h:186:7: note: type 'struct RFM69' itself violates the C++ One Definition Rule
class RFM69 {
^
.pio\libdeps\pro8MHzatmega328\RFM69/RFM69.h:186:7: note: the incompatible type is defined here
class RFM69 {
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:60:6: note: 'initialize' was previously declared here
bool RFM69::initialize(uint8_t freqBand, uint16_t nodeID, uint8_t networkID)
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:60:6: note: code may be misoptimized unless -fno-strict-aliasing is used
.pio\libdeps\pro8MHzatmega328\RFM69/RFM69.h:216:10: warning: 'encrypt' violates the C++ One Definition Rule [-Wodr]
void encrypt(const char* key);
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:503:6: note: implicit this pointer type mismatch
void RFM69::encrypt(const char* key) {
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.h:186:7: note: type 'struct RFM69' itself violates the C++ One Definition Rule
class RFM69 {
^
.pio\libdeps\pro8MHzatmega328\RFM69/RFM69.h:186:7: note: the incompatible type is defined here
class RFM69 {
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:503:6: note: 'encrypt' was previously declared here
void RFM69::encrypt(const char* key) {
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:503:6: note: code may be misoptimized unless -fno-strict-aliasing is used
.pio\libdeps\pro8MHzatmega328\RFM69/RFM69.h:227:10: warning: 'sleep' violates the C++ One Definition Rule [-Wodr]
void sleep();
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:215:6: note: implicit this pointer type mismatch
void RFM69::sleep() {
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.h:186:7: note: type 'struct RFM69' itself violates the C++ One Definition Rule
class RFM69 {
^
.pio\libdeps\pro8MHzatmega328\RFM69/RFM69.h:186:7: note: the incompatible type is defined here
class RFM69 {
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:215:6: note: 'sleep' was previously declared here
void RFM69::sleep() {
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:215:6: note: code may be misoptimized unless -fno-strict-aliasing is used
.pio\libdeps\pro8MHzatmega328\RFM69/RFM69.h:201:5: warning: '__comp_ctor ' violates the C++ One Definition Rule [-Wodr]
RFM69(uint8_t slaveSelectPin=RF69_SPI_CS, uint8_t interruptPin=RF69_IRQ_PIN, bool isRFM69HW_HCW=false, SPIClass *spi=nullptr);
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:42:1: note: implicit this pointer type mismatch
RFM69::RFM69(uint8_t slaveSelectPin, uint8_t interruptPin, bool isRFM69HW_HCW, SPIClass *spi) {
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.h:186:7: note: type 'struct RFM69' itself violates the C++ One Definition Rule
class RFM69 {
^
.pio\libdeps\pro8MHzatmega328\RFM69/RFM69.h:186:7: note: the incompatible type is defined here
class RFM69 {
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:42:1: note: '__comp_ctor ' was previously declared here
RFM69::RFM69(uint8_t slaveSelectPin, uint8_t interruptPin, bool isRFM69HW_HCW, SPIClass *spi) {
^
.pio\libdeps\pro8MHzatmega328\RFM69\RFM69.cpp:42:1: note: code may be misoptimized unless -fno-strict-aliasing is used
C:\Users\LennArt\AppData\Local\Temp\ccb4dJLO.ltrans0.ltrans.o: In function `SensorTempHum::handle(Payload*)':
<artificial>:(.text+0x127e): undefined reference to `RFM69::listenModeEnd()'
C:\Users\LennArt\AppData\Local\Temp\ccb4dJLO.ltrans0.ltrans.o: In function `main':
<artificial>:(.text.startup+0x74e): undefined reference to `RFM69::listenModeSetDurations(unsigned long&, unsigned long&)'
<artificial>:(.text.startup+0x75a): undefined reference to `RFM69::listenModeStart()'
<artificial>:(.text.startup+0x792): undefined reference to `RFM69::listenModeEnd()'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\pro8MHzatmega328\firmware.elf] Error 1

I double checked if the RFM69-library is included elsewhere in the project an this is not the case.
What about the library itself? You have to compile both your project and the library with the exactly the same version of RFM69.h.
It looks like you added RF69_LISTENMODE_ENABLE into your project but are using the library without it, meaning RFM69.cpp saw different header file with incompatible types.
Of course in better world the library should not rely on these macros tricks.
Add the macro definition to the Makefile, CMakeLists or whatever build system you are using for your project and the library.

Related

Compile errors in Tensorflow Lite Micro framework when trying to integrate Tensorflow Lite Micro to my ESP32 Arduino project

Hi stackoverflow community,
I am trying to get a project leveraging Tensorflow Lite Micro to run on my ESP32 using PlatformIO and the Arduino framework (not ESP-IDF). Basically, I followed the guide in this medium post https://towardsdatascience.com/tensorflow-meet-the-esp32-3ac36d7f32c7 and then included everything in my already existing ESP32 project.
My project was compiling fine prior to the integration of Tensorflow Lite Micro but since integrating it, I am getting the following compile errors which seem to be related to the Tensorflow framework itself. When I uncomment everything related to Tensorflow, it compiles fine. But just when only including the following header files, it breaks:
#include "tensorflow/lite/micro/kernels/micro_ops.h"
#include "tensorflow/lite/micro/micro_error_reporter.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/micro/micro_mutable_op_resolver.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/version.h"
Does someone know where these errors come from and what I can do to solve those?
Here is the error trace:
In file included from /Users/XXX/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiClient.h:24:0,
from /Users/XXX/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFi.h:37,
from src/main.cpp:3:
/Users/XXX/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:64:17: error: expected identifier before numeric constant
#define DEFAULT 1
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:31:5: note: in expansion of macro 'DEFAULT'
DEFAULT = 1,
^
/Users/XXX/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:64:17: error: expected '}' before numeric constant
#define DEFAULT 1
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:31:5: note: in expansion of macro 'DEFAULT'
DEFAULT = 1,
^
/Users/XXX/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:64:17: error: expected unqualified-id before numeric constant
#define DEFAULT 1
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:31:5: note: in expansion of macro 'DEFAULT'
DEFAULT = 1,
^
In file included from lib/tfmicro/tensorflow/lite/micro/micro_interpreter.h:24:0,
from src/main.cpp:12:
lib/tfmicro/tensorflow/lite/core/api/profiler.h:51:21: error: declaration of '~tflite::Profiler' as non-member
virtual ~Profiler() {}
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:61:48: error: 'EventType' has not been declared
virtual uint32_t BeginEvent(const char* tag, EventType event_type,
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:63:54: error: 'virtual' outside class declaration
int64_t event_metadata2) = 0;
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:63:58: error: function 'uint32_t tflite::BeginEvent(const char*, int, int64_t, int64_t)' is initialized like a variable
int64_t event_metadata2) = 0;
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:65:40: error: 'EventType' has not been declared
uint32_t BeginEvent(const char* tag, EventType event_type,
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:74:48: error: 'virtual' outside class declaration
int64_t event_metadata2) {}
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:76:46: error: 'virtual' outside class declaration
virtual void EndEvent(uint32_t event_handle) = 0;
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:76:50: error: function 'void tflite::EndEvent(uint32_t)' is initialized like a variable
virtual void EndEvent(uint32_t event_handle) = 0;
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:85:34: error: 'EventType' has not been declared
void AddEvent(const char* tag, EventType event_type, uint64_t start,
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h: In function 'void tflite::AddEvent(const char*, int, uint64_t, uint64_t, int64_t)':
lib/tfmicro/tensorflow/lite/core/api/profiler.h:88:35: error: too many arguments to function 'void tflite::AddEvent(const char*, int, uint64_t, uint64_t, int64_t)'
/*event_metadata2*/ 0);
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:85:8: note: declared here
void AddEvent(const char* tag, EventType event_type, uint64_t start,
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h: At global scope:
lib/tfmicro/tensorflow/lite/core/api/profiler.h:91:42: error: 'EventType' has not been declared
virtual void AddEvent(const char* tag, EventType event_type, uint64_t start,
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:93:48: error: 'virtual' outside class declaration
int64_t event_metadata2) {}
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:95:2: error: expected unqualified-id before 'protected'
protected:
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:105:25: error: expected ')' before '*' token
ScopedProfile(Profiler* profiler, const char* tag,
^
src/main.cpp:202:1: error: expected '}' at end of input
}
^
src/main.cpp:202:1: error: expected unqualified-id at end of input
*** [.pio/build/esp32cam/src/main.cpp.o] Error 1
Today I faced a similar problem. I solved it by using TensorFlowLite_ESP32 library instead of Arduino_TensorFlowLite. You need to download this library and add the line #include <TensorFlowLite_ESP32.h>. I hope this helps you too
I resolved this for now by switching from the Arduino framework to the ESP-IDF framework. With this, it works like a charm.

std::basic_stream not supporting char16_t in Xcode (OS X target)

First, I want to predicate this issue as only being a problem on OS X using Xcode and the clang compiler. The following code compiles with gcc (9 and 10) on Linux (RH8) and Visual Studio (2019). However it will not compile on Xcode (13.1) with clang on Big Sur targeting OS X.
std::basic_fstream<char16_t> stream;
rapidjson::BasicIStreamWrapper<std::basic_fstream<char16_t>> iwrapper(stream);
rapidjson::GenericStreamWrapper<
rapidjson::BasicIStreamWrapper<std::basic_fstream<char16_t>>,
rapidjson::UTF16<char16_t>> gwrapper(iwrapper);
I believe the use of the rapidjson library here is irrelevant to the issue.
When I try to use gwrapper, I get a compiler error:
No matching constructor for initialization of 'std::basic_istream<char16_t>::sentry'
...
13. Candidate constructor not viable: requires 1 argument, but 2 were provided
This appears to come from the stream's constructor:
template<class _CharT, class _Traits>
typename basic_istream<_CharT, _Traits>::int_type
basic_istream<_CharT, _Traits>::get()
{
ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
int_type __r = traits_type::eof();
sentry __s(*this, true); <---- HERE
...
Pointing to line 297 (at least Apple's version of the file) of istream. This is where a single argument constructor sentry is defined.
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry
{
bool __ok_;
sentry(const sentry&); // = delete; <-- ERROR POINTS HERE
sentry& operator=(const sentry&); // = delete;
public:
explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
// ~sentry() = default;
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_EXPLICIT
operator bool() const {return __ok_;}
};
It appears to want the explicitly defined constructor:
explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
That datatype is char16_t for the stream, and hence for the sentry as well. The compiler isn't picking the correct constructor. At least, that is my conclusion at this point. I find it unlikely that a system header file or the system library is incorrectly written (though not impossible), leaving me wondering what I am doing wrong.
As requested I tried it without the library code. Different error but still points to the same place.
The new code ..
#include <fstream>
#include <string>
#include <ctype.h>
int main(int argc, const char * argv[]) {
std::basic_fstream<char16_t> s;
s.peek();
return 0;
}
The errors...
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/istream:325:26: Implicit instantiation of undefined template 'std::ctype<char16_t>'
/Users/user/dev/cti/cti/clang_tests/clang_tests/main.cpp:6:10: in file included from /Users/user/dev/cti/cti/clang_tests/clang_tests/main.cpp:6:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/fstream:185:10: in file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/fstream:185:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/istream:1018:12: In instantiation of member function 'std::basic_istream<char16_t>::sentry::sentry' requested here
/Users/user/dev/cti/cti/clang_tests/clang_tests/main.cpp:15:7: In instantiation of member function 'std::basic_istream<char16_t>::peek' requested here
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/__locale:519:52: Template is declared here
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/__locale:254:54: Implicit instantiation of undefined template 'std::ctype<char16_t>'
/Users/user/dev/cti/cti/clang_tests/clang_tests/main.cpp:6:10: in file included from /Users/user/dev/cti/cti/clang_tests/clang_tests/main.cpp:6:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/fstream:184:10: in file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/fstream:184:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/ostream:137:10: in file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/ostream:137:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/ios:215:10: in file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/ios:215:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/istream:321:41: In instantiation of function template specialization 'std::use_facetstd::ctype<char16_t>' requested here
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/istream:1018:12: In instantiation of member function 'std::basic_istream<char16_t>::sentry::sentry' requested here
/Users/user/dev/cti/cti/clang_tests/clang_tests/main.cpp:15:7: In instantiation of member function 'std::basic_istream<char16_t>::peek' requested here
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/__locale:519:52: Template is declared here

How to resolve error: invalid use of incomplete type ‘GdkSurface {aka struct _GdkSurface}’?

Questions about incomplete type errors have already been asked here often, but all of the solutions provided there do not help in my case. Adding a forward declaration makes no sense, as GdkSurface has been forward declared already in the Gdk headers. Including the appropriate headers has already been done. Following the error producing code portion + includes.
#include <gdkmm/display.h>
#include <gdkmm/surface.h>
extern "C" {
#include <gdk/x11/gdkx.h>
#include <gdk/gdk.h>
}
extern "C" {
void surface_move(Gdk::Surface* psurface, int x, int y) {
#ifdef GDK_WINDOWING_X11
GdkSurface* surface = psurface->gobj();
GdkSurface *impl = GDK_X11_SURFACE(surface);
XMoveWindow(GDK_SURFACE_XDISPLAY (surface), GDK_SURFACE_XID (surface), x * impl->surface_scale, y * impl->surface_scale);
#endif
}
}
Here are the complete errors:
src/utils.cpp: In function ‘void Gdk::surface_move(Gdk::Surface*, int, int)’:
src/utils.cpp:9:83: error: invalid use of incomplete type ‘GdkSurface {aka struct _GdkSurface}’
(GDK_SURFACE_XDISPLAY (surface), GDK_SURFACE_XID (surface), x * impl->surface_scale, y * impl->surface_scale);
^~
In file included from /home/user/.local/built/include/gtk-4.0/gdk/gdkapplaunchcontext.h:29:0,
from /home/user/.local/built/include/gtk-4.0/gdk/gdk.h:30,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/enums.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/event.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/display.h:30,
from ./include/libgdp/utils.hpp:3,
from src/utils.cpp:1:
/home/user/.local/built/include/gtk-4.0/gdk/gdktypes.h:97:16: note: forward declaration of ‘GdkSurface {aka struct _GdkSurface}’
typedef struct _GdkSurface GdkSurface;
^~~~~~~~~~~
src/utils.cpp:9:108: error: invalid use of incomplete type ‘GdkSurface {aka struct _GdkSurface}’
rface), GDK_SURFACE_XID (surface), x * impl->surface_scale, y * impl->surface_scale);
^~
In file included from /home/user/.local/built/include/gtk-4.0/gdk/gdkapplaunchcontext.h:29:0,
from /home/user/.local/built/include/gtk-4.0/gdk/gdk.h:30,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/enums.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/event.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/display.h:30,
from ./include/libgdp/utils.hpp:3,
from src/utils.cpp:1:
/home/user/.local/built/include/gtk-4.0/gdk/gdktypes.h:97:16: note: forward declaration of ‘GdkSurface {aka struct _GdkSurface}’
typedef struct _GdkSurface GdkSurface;
^~~~~~~~~~~
I built Gdk, Gtk, Gdkmm and Gtkmm with JHbuild.
It seems this type is private to GDK by design (only a forward declaration is provided). From the GDK4 documentation:
The GdkSurface struct contains only private fields and should not
be accessed directly.
See here for the header in which it is defined (which is not distributed). This is why you get these errors, all you have is a forward declaration to pass around pointers and references. All access to data members is forbidden.
To solve this, you have to use functions that work on surfaces (that are public), such as gdk_surface_get_scale_factor or something similar instead of trying to access data members directly.

Linking TensorFlow to C++. Protobuf (/usr/local/include/google/protobuf)

System information
Have I written custom code: Custom project
OS Platform and Distribution: macOS Sierra (10.12.6)
TensorFlow installed from: Source
TensorFlow version: Git tagged at 1.3 and master at d27ed9c
Python version: Python 2.7.13 :: Anaconda 4.4.0
Bazel version: 0.5.3_1-homebrew
Protobuf version: 3.3.2-homebrew
CUDA/cuDNN version: N/A
GPU model and memory: N/A
Exact command to reproduce:
Problem description
I compiled TensorFlow source code for Python & C++ API bindings following the steps shown in http://www.blitzblit.com/2017/06/11/creating-tensorflow-c-headers-and-libraries/ (We have to take into account that this tutorial is not updated). After compiling the TF source code I include the TF library in the C++ project:
#include <tensorflow/core/public/session.h>
Finally, I compile the C++ project (Until here everything seems fine). Then, when I try to launch the C++ code I get the following message:
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/arcadillanzacarmona/Desktop/FaceSDK/ cmake-build-debug --target FaceSDK -- -j 2
[ 96%] Built target dlib
[ 96%] Building CXX object CMakeFiles/FaceSDK.dir/main.cpp.o
clang: warning: -lcurl: 'linker' input unused [-Wunused-command-line-argument]
In file included from /Users/arcadillanzacarmona/Desktop/FaceSDK/main.cpp:33:
In file included from /usr/local/include/tensorflow/core/public/session.h:22:
In file included from /usr/local/include/tensorflow/core/framework/device_attributes.pb.h:29:
/usr/local/include/google/protobuf/repeated_field.h:328:33: error: expected a qualified name after 'typename'
template <typename It, typename VoidPtr> class RepeatedPtrOverPtrsIterator;
^
/opt/local/include/gif_lib.h:286:17: note: expanded from macro 'VoidPtr'
#define VoidPtr void *
^
In file included from /Users/arcadillanzacarmona/Desktop/FaceSDK/main.cpp:33:
In file included from /usr/local/include/tensorflow/core/public/session.h:22:
In file included from /usr/local/include/tensorflow/core/framework/device_attributes.pb.h:29:
/usr/local/include/google/protobuf/repeated_field.h:328:33: error: expected ',' or '>' in template-parameter-list
/opt/local/include/gif_lib.h:286:17: note: expanded from macro 'VoidPtr'
#define VoidPtr void *
^
In file included from /Users/arcadillanzacarmona/Desktop/FaceSDK/main.cpp:33:
In file included from /usr/local/include/tensorflow/core/public/session.h:22:
In file included from /usr/local/include/tensorflow/core/framework/device_attributes.pb.h:29:
/usr/local/include/google/protobuf/repeated_field.h:864:59: error: template argument for non-type template parameter must be an expression
typedef internal::RepeatedPtrOverPtrsIterator<Element*, void*>
^~~~~
/usr/local/include/google/protobuf/repeated_field.h:328:33: note: template parameter is declared here
template <typename It, typename VoidPtr> class RepeatedPtrOverPtrsIterator;
^
/opt/local/include/gif_lib.h:286:17: note: expanded from macro 'VoidPtr'
#define VoidPtr void *
^
In file included from /Users/arcadillanzacarmona/Desktop/FaceSDK/main.cpp:33:
In file included from /usr/local/include/tensorflow/core/public/session.h:22:
In file included from /usr/local/include/tensorflow/core/framework/device_attributes.pb.h:29:
/usr/local/include/google/protobuf/repeated_field.h:867:55: error: template argument for non-type template parameter must be an expression
const void* const>
^~~~~
/usr/local/include/google/protobuf/repeated_field.h:328:33: note: template parameter is declared here
template <typename It, typename VoidPtr> class RepeatedPtrOverPtrsIterator;
^
/opt/local/include/gif_lib.h:286:17: note: expanded from macro 'VoidPtr'
#define VoidPtr void *
^
In file included from /Users/arcadillanzacarmona/Desktop/FaceSDK/main.cpp:33:
In file included from /usr/local/include/tensorflow/core/public/session.h:22:
In file included from /usr/local/include/tensorflow/core/framework/device_attributes.pb.h:29:
/usr/local/include/google/protobuf/repeated_field.h:2258:38: error: expected a qualified name after 'typename'
template <typename Element, typename VoidPtr>
^
/opt/local/include/gif_lib.h:286:17: note: expanded from macro 'VoidPtr'
#define VoidPtr void *
^
In file included from /Users/arcadillanzacarmona/Desktop/FaceSDK/main.cpp:33:
In file included from /usr/local/include/tensorflow/core/public/session.h:22:
In file included from /usr/local/include/tensorflow/core/framework/device_attributes.pb.h:29:
/usr/local/include/google/protobuf/repeated_field.h:2258:38: error: expected ',' or '>' in template-parameter-list
/opt/local/include/gif_lib.h:286:17: note: expanded from macro 'VoidPtr'
#define VoidPtr void *
^
In file included from /Users/arcadillanzacarmona/Desktop/FaceSDK/main.cpp:33:
In file included from /usr/local/include/tensorflow/core/public/session.h:22:
In file included from /usr/local/include/tensorflow/core/framework/device_attributes.pb.h:29:
/usr/local/include/google/protobuf/repeated_field.h:2262:48: error: template argument for non-type template parameter must be an expression
typedef RepeatedPtrOverPtrsIterator<Element, VoidPtr> iterator;
^~~~~~~
/opt/local/include/gif_lib.h:286:17: note: expanded from macro 'VoidPtr'
#define VoidPtr void *
^~~~~~
/usr/local/include/google/protobuf/repeated_field.h:2258:38: note: template parameter is declared here
template <typename Element, typename VoidPtr>
^
/opt/local/include/gif_lib.h:286:17: note: expanded from macro 'VoidPtr'
#define VoidPtr void *
^
In file included from /Users/arcadillanzacarmona/Desktop/FaceSDK/main.cpp:33:
In file included from /usr/local/include/tensorflow/core/public/session.h:22:
In file included from /usr/local/include/tensorflow/core/framework/device_attributes.pb.h:29:
/usr/local/include/google/protobuf/repeated_field.h:2289:61: error: member reference base type 'const iterator' ( aka 'const int') is not a structure or union
bool operator==(const iterator& x) const { return it_ == x.it_; }
~^~~~
/usr/local/include/google/protobuf/repeated_field.h:2290:61: error: member reference base type 'const iterator' ( aka 'const int') is not a structure or union
bool operator!=(const iterator& x) const { return it_ != x.it_; }
~^~~~
/usr/local/include/google/protobuf/repeated_field.h:2293:59: error: member reference base type 'const iterator' ( aka 'const int') is not a structure or union
bool operator<(const iterator& x) const { return it_ < x.it_; }
~^~~~
/usr/local/include/google/protobuf/repeated_field.h:2294:61: error: member reference base type 'const iterator' ( aka 'const int') is not a structure or union
bool operator<=(const iterator& x) const { return it_ <= x.it_; }
~^~~~
/usr/local/include/google/protobuf/repeated_field.h:2295:59: error: member reference base type 'const iterator' ( aka 'const int') is not a structure or union
bool operator>(const iterator& x) const { return it_ > x.it_; }
~^~~~
/usr/local/include/google/protobuf/repeated_field.h:2296:61: error: member reference base type 'const iterator' ( aka 'const int') is not a structure or union
bool operator>=(const iterator& x) const { return it_ >= x.it_; }
~^~~~
/usr/local/include/google/protobuf/repeated_field.h:2324:70: error: member reference base type 'const iterator' ( aka 'const int') is not a structure or union
difference_type operator-(const iterator& x) const { return it_ - x.it_; }
~^~~~
In file included from /Users/arcadillanzacarmona/Desktop/FaceSDK/main.cpp:33:
In file included from /usr/local/include/tensorflow/core/public/session.h:24:
In file included from /usr/local/include/tensorflow/core/framework/tensor.h:21:
In file included from /usr/local/include/tensorflow/core/framework/allocator.h:26:
In file included from /usr/local/include/tensorflow/core/framework/variant.h:30:
In file included from /usr/local/include/tensorflow/core/platform/mutex.h:31:
/usr/local/include/tensorflow/core/platform/default/mutex.h:25:10: fatal error: 'nsync_cv.h' file not found
#include "nsync_cv.h"
^
15 errors generated.
gmake[3]: *** [CMakeFiles/FaceSDK.dir/build.make:63: CMakeFiles/FaceSDK.dir/main.cpp.o] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:68: CMakeFiles/FaceSDK.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/FaceSDK.dir/rule] Error 2
gmake: *** [Makefile:118: FaceSDK] Error 2
Can anyone help me? Seems that the main problem is in the google/protobuf.
The problem is that gif_lib.h and that protobuf header file are incompatible. More specifically, the problem is that gif_lib.h uses the preprocessor to define a macro called VoidPtr, and then the protobuf header uses VoidPtr as an identifier. The fault firmly lays with gif_lib, not protobuf! Preprocessor macros, by convention, are usually uppercase, should include the library name, and should be avoided entirely if possible (in this case, wouldn't a typedef have done?).
Here are some possible workarounds:
Include the protobuf header (or something that includes it, like a TensorFlow header) before the gif_lib.h one (or, again, something that includes it).
After including gif_lib.h, write #undef VoidPtr on a separate line (but this might cause other mysterious problems, depending on how gif_lib.h is implemented.
Do not #include those both of those two headers from any one of your files; hide them behind your own interfaces.
File a bug with whoever wrote gif_lib and get them to stop using the proprocessor in such a dangerous way.
Use a better designed library in place of gif_lib.
I had the similar issue which is solved by changing compiler and using a different version of C++(i.e. from clang to g++-5, g++-7, etc.). I suggest that you can try to solve it in this way. Sorry for not able to give a direct solution.
For the error about nsync_cv, alc1218's solution on this post may help, which is changing the file mutex.h as follows:
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_PLATFORM_DEFAULT_MUTEX_H_
#define TENSORFLOW_PLATFORM_DEFAULT_MUTEX_H_
// IWYU pragma: private, include "third_party/tensorflow/core/platform/mutex.h"
// IWYU pragma: friend third_party/tensorflow/core/platform/mutex.h
#include <chrono>
#include <condition_variable>
#include <mutex>
#include "tensorflow/core/platform/thread_annotations.h"
namespace tensorflow {
#undef mutex_lock
enum LinkerInitialized { LINKER_INITIALIZED };
// A class that wraps around the std::mutex implementation, only adding an
// additional LinkerInitialized constructor interface.
class LOCKABLE mutex : public std::mutex {
public:
mutex() {}
// The default implementation of std::mutex is safe to use after the linker
// initializations
explicit mutex(LinkerInitialized x) {}
void lock() ACQUIRE() { std::mutex::lock(); }
bool try_lock() EXCLUSIVE_TRYLOCK_FUNCTION(true) {
return std::mutex::try_lock();
};
void unlock() RELEASE() { std::mutex::unlock(); }
};
class SCOPED_LOCKABLE mutex_lock : public std::unique_lock<std::mutex> {
public:
mutex_lock(class mutex& m) ACQUIRE(m) : std::unique_lock<std::mutex>(m) {}
mutex_lock(class mutex& m, std::try_to_lock_t t) ACQUIRE(m)
: std::unique_lock<std::mutex>(m, t) {}
mutex_lock(mutex_lock&& ml) noexcept
: std::unique_lock<std::mutex>(std::move(ml)) {}
~mutex_lock() RELEASE() {}
};
// Catch bug where variable name is omitted, e.g. mutex_lock (mu);
#define mutex_lock(x) static_assert(0, "mutex_lock_decl_missing_var_name");
using std::condition_variable;
inline ConditionResult WaitForMilliseconds(mutex_lock* mu,
condition_variable* cv, int64 ms) {
std::cv_status s = cv->wait_for(*mu, std::chrono::milliseconds(ms));
return (s == std::cv_status::timeout) ? kCond_Timeout : kCond_MaybeNotified;
}
} // namespace tensorflow
#endif // TENSORFLOW_PLATFORM_DEFAULT_MUTEX_H_
or simply find where your "nsync_cv" is and include the whole path.

Building iotivity on mac

According to the docs, Mac should be supported but when attempting to build iotivity some headers are used that I think are posix specific.
➜ iotivity git:(master) ✗ scons SYS_VERSION=10.12
scons: Reading SConscript files ...
Checking for POSIX Thread Support...(cached) yes
HEAD is now at acf202a Fix stack corruption due to calling convention mismatch
*********************************** Info: *****************************************
* Using FORKED copy of libCoap located in: *
* resource/csdk/connectivity/lib/libcoap-4.1.1 *
***********************************************************************************
Given Transport is ALL
Given OS is darwin
BUILD_SAMPLE is ON
MQ flag is OFF
Reading ca script ALL
Reading common folder script
Reading util folder script
Copied IoTivity version of config.h to /Users/zcourts/projects/iotivity/extlibs/mbedtls/mbedtls/include/mbedtls/config.h
Reading IP adapter script
Reading IP adapter script
Include path is ['../api', '/usr/local/include', '/Users/zcourts/projects/iotivity/deps/darwin/include', '/Users/zcourts/projects/iotivity/extlibs/tinycbor/tinycbor/src', '/Users/zcourts/projects/iotivity/resource/c_common', '/Users/zcourts/projects/iotivity/out/darwin/x86_64/release/resource/c_common/oic_malloc/include', '/Users/zcourts/projects/iotivity/out/darwin/x86_64/release/resource/c_common/oic_string/include', '/Users/zcourts/projects/iotivity/out/darwin/x86_64/release/resource/c_common/oic_time/include', '/Users/zcourts/projects/iotivity/out/darwin/x86_64/release/resource/c_common/ocatomic/include', '/Users/zcourts/projects/iotivity/out/darwin/x86_64/release/resource/c_common/ocrandom/include', '/Users/zcourts/projects/iotivity/out/darwin/x86_64/release/resource/c_common/octhread/include', '/Users/zcourts/projects/iotivity/out/darwin/x86_64/release/resource/c_common/oic_platform/include', '/Users/zcourts/projects/iotivity/out/darwin/x86_64/release/resource/c_common/octimer/include', '#/extlibs/mbedtls/mbedtls/include', '/Users/zcourts/projects/iotivity/out/darwin/x86_64/release/resource/csdk/logger/include', '#/resource/c_common', '#resource/csdk/connectivity/lib/libcoap-4.1.1/include', '../inc', '/Users/zcourts/projects/iotivity/resource/csdk/logger/include', '../common/inc', '../util/inc', '#resource/c_common/octhread/include/', '#resource/csdk/connectivity/common/inc/', '#resource/csdk/logger/include/', '#extlibs/mbedtls/mbedtls/include', '#/resource/c_common/octimer/include', '/Users/zcourts/projects/iotivity/resource/csdk/security/include', '../external/inc']
Files path is ['/Users/zcourts/projects/iotivity/resource/csdk/connectivity/common/src/uarraylist.c', '/Users/zcourts/projects/iotivity/resource/csdk/connectivity/common/src/ulinklist.c', '/Users/zcourts/projects/iotivity/resource/csdk/connectivity/common/src/uqueue.c', '/Users/zcourts/projects/iotivity/resource/csdk/connectivity/common/src/caremotehandler.c', '/Users/zcourts/projects/iotivity/resource/csdk/connectivity/common/src/cathreadpool_pthreads.c', '/Users/zcourts/projects/iotivity/resource/csdk/connectivity/util/src/cautilinterface.c', './adapter_util/caadapterutils.c', './adapter_util/cafragmentation.c', './adapter_util/ca_adapter_net_ssl.c', './cablockwisetransfer.c', './caconnectivitymanager.c', './cainterfacecontroller.c', './camessagehandler.c', './canetworkconfigurator.c', './caprotocolmessage.c', './caqueueingthread.c', './caretransmission.c', '/Users/zcourts/projects/iotivity/resource/csdk/connectivity/src/ip_adapter/caipadapter.c', '/Users/zcourts/projects/iotivity/resource/csdk/connectivity/src/ip_adapter/caipserver.c', '/Users/zcourts/projects/iotivity/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c']
*** Checking for installation of google unit test 1.7.0 ***
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: out/darwin/x86_64/release
Compiling out/darwin/x86_64/release/resource/c_common/octhread/src/posix/octhread.o
resource/c_common/octhread/src/posix/octhread.c:90:5: error: unknown type name 'pthread_mutex_t'; did you mean 'pthread_attr_t'?
pthread_mutex_t mutex;
^~~~~~~~~~~~~~~
pthread_attr_t
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk//usr/include/sys/_pthread/_pthread_attr_t.h:30:33: note: 'pthread_attr_t' declared here
typedef __darwin_pthread_attr_t pthread_attr_t;
^
resource/c_common/octhread/src/posix/octhread.c:103:5: error: unknown type name 'pthread_cond_t'; did you mean 'pthread_attr_t'?
pthread_cond_t cond;
^~~~~~~~~~~~~~
pthread_attr_t
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk//usr/include/sys/_pthread/_pthread_attr_t.h:30:33: note: 'pthread_attr_t' declared here
typedef __darwin_pthread_attr_t pthread_attr_t;
^
resource/c_common/octhread/src/posix/octhread.c:104:5: error: unknown type name 'pthread_condattr_t'; did you mean 'pthread_attr_t'?
pthread_condattr_t condattr;
^~~~~~~~~~~~~~~~~~
pthread_attr_t
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk//usr/include/sys/_pthread/_pthread_attr_t.h:30:33: note: 'pthread_attr_t' declared here
typedef __darwin_pthread_attr_t pthread_attr_t;
^
resource/c_common/octhread/src/posix/octhread.c:109:5: error: unknown type name 'pthread_t'
pthread_t thread;
^
resource/c_common/octhread/src/posix/octhread.c:128:22: warning: implicit declaration of function 'pthread_create' is invalid in C99 [-Wimplicit-function-declaration]
int result = pthread_create(&threadInfo->thread, NULL, start_routine, arg);
^
resource/c_common/octhread/src/posix/octhread.c:170:19: warning: implicit declaration of function 'pthread_join' is invalid in C99 [-Wimplicit-function-declaration]
int joinres = pthread_join(threadInfo->thread, NULL);
^
resource/c_common/octhread/src/posix/octhread.c:187:17: warning: implicit declaration of function 'pthread_mutex_init' is invalid in C99 [-Wimplicit-function-declaration]
int ret=pthread_mutex_init(&(mutexInfo->mutex), PTHREAD_MUTEX_DEFAULT);
^
resource/c_common/octhread/src/posix/octhread.c:187:57: error: use of undeclared identifier 'PTHREAD_MUTEX_DEFAULT'
int ret=pthread_mutex_init(&(mutexInfo->mutex), PTHREAD_MUTEX_DEFAULT);
^
resource/c_common/octhread/src/posix/octhread.c:215:19: warning: implicit declaration of function 'pthread_mutex_destroy' is invalid in C99 [-Wimplicit-function-declaration]
int ret = pthread_mutex_destroy(&mutexInfo->mutex);
^
resource/c_common/octhread/src/posix/octhread.c:239:19: warning: implicit declaration of function 'pthread_mutex_lock' is invalid in C99 [-Wimplicit-function-declaration]
int ret = pthread_mutex_lock(&mutexInfo->mutex);
^
resource/c_common/octhread/src/posix/octhread.c:273:19: warning: implicit declaration of function 'pthread_mutex_unlock' is invalid in C99 [-Wimplicit-function-declaration]
int ret = pthread_mutex_unlock(&mutexInfo->mutex);
^
resource/c_common/octhread/src/posix/octhread.c:314:19: warning: implicit declaration of function 'pthread_condattr_init' is invalid in C99 [-Wimplicit-function-declaration]
int ret = pthread_condattr_init(&(eventInfo->condattr));
^
resource/c_common/octhread/src/posix/octhread.c:342:15: warning: implicit declaration of function 'pthread_cond_init' is invalid in C99 [-Wimplicit-function-declaration]
ret = pthread_cond_init(&(eventInfo->cond), &(eventInfo->condattr));
^
resource/c_common/octhread/src/posix/octhread.c:350:13: warning: implicit declaration of function 'pthread_condattr_destroy' is invalid in C99 [-Wimplicit-function-declaration]
pthread_condattr_destroy(&(eventInfo->condattr));
^
resource/c_common/octhread/src/posix/octhread.c:367:19: warning: implicit declaration of function 'pthread_cond_destroy' is invalid in C99 [-Wimplicit-function-declaration]
int ret = pthread_cond_destroy(&(eventInfo->cond));
^
resource/c_common/octhread/src/posix/octhread.c:390:19: warning: implicit declaration of function 'pthread_cond_signal' is invalid in C99 [-Wimplicit-function-declaration]
int ret = pthread_cond_signal(&(eventInfo->cond));
^
resource/c_common/octhread/src/posix/octhread.c:407:19: warning: implicit declaration of function 'pthread_cond_broadcast' is invalid in C99 [-Wimplicit-function-declaration]
int ret = pthread_cond_broadcast(&(eventInfo->cond));
^
resource/c_common/octhread/src/posix/octhread.c:431:17: error: incomplete result type 'struct timespec' in function definition
struct timespec oc_get_current_time()
^
resource/c_common/octhread/src/posix/octhread.c:431:8: note: forward declaration of 'struct timespec'
struct timespec oc_get_current_time()
^
resource/c_common/octhread/src/posix/octhread.c:439:5: warning: implicit declaration of function 'gettimeofday' is invalid in C99 [-Wimplicit-function-declaration]
gettimeofday(&tv, NULL);
^
resource/c_common/octhread/src/posix/octhread.c:440:21: error: variable has incomplete type 'struct timespec'
struct timespec ts;
^
resource/c_common/octhread/src/posix/octhread.c:431:8: note: forward declaration of 'struct timespec'
struct timespec oc_get_current_time()
^
resource/c_common/octhread/src/posix/octhread.c:448:5: error: unknown type name 'time_t'; did you mean 'size_t'?
time_t secPart = microseconds/USECS_PER_SEC;
^~~~~~
size_t
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk//usr/include/sys/_types/_size_t.h:30:32: note: 'size_t' declared here
typedef __darwin_size_t size_t;
^
resource/c_common/octhread/src/posix/octhread.c:450:26: error: incomplete definition of type 'struct timespec'
uint64_t totalNs = ts->tv_nsec + nsecPart;
~~^
resource/c_common/octhread/src/posix/octhread.c:431:8: note: forward declaration of 'struct timespec'
struct timespec oc_get_current_time()
^
resource/c_common/octhread/src/posix/octhread.c:451:5: error: unknown type name 'time_t'; did you mean 'size_t'?
time_t secOfNs = totalNs/NANOSECS_PER_SEC;
^~~~~~
size_t
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk//usr/include/sys/_types/_size_t.h:30:32: note: 'size_t' declared here
typedef __darwin_size_t size_t;
^
resource/c_common/octhread/src/posix/octhread.c:453:7: error: incomplete definition of type 'struct timespec'
ts->tv_nsec = (totalNs)% NANOSECS_PER_SEC;
~~^
resource/c_common/octhread/src/posix/octhread.c:431:8: note: forward declaration of 'struct timespec'
struct timespec oc_get_current_time()
^
resource/c_common/octhread/src/posix/octhread.c:454:7: error: incomplete definition of type 'struct timespec'
ts->tv_sec += secPart + secOfNs;
~~^
resource/c_common/octhread/src/posix/octhread.c:431:8: note: forward declaration of 'struct timespec'
struct timespec oc_get_current_time()
^
resource/c_common/octhread/src/posix/octhread.c:479:25: error: variable has incomplete type 'struct timespec'
struct timespec abstime = { .tv_sec = 0 };
^
resource/c_common/octhread/src/posix/octhread.c:431:8: note: forward declaration of 'struct timespec'
struct timespec oc_get_current_time()
^
resource/c_common/octhread/src/posix/octhread.c:495:19: warning: implicit declaration of function 'pthread_cond_timedwait' is invalid in C99 [-Wimplicit-function-declaration]
ret = pthread_cond_timedwait(&(eventInfo->cond), &(mutexInfo->mutex), &abstime);
^
resource/c_common/octhread/src/posix/octhread.c:520:19: warning: implicit declaration of function 'pthread_cond_wait' is invalid in C99 [-Wimplicit-function-declaration]
int ret = pthread_cond_wait(&eventInfo->cond, &mutexInfo->mutex);
^
15 warnings and 13 errors generated.
scons: *** [out/darwin/x86_64/release/resource/c_common/octhread/src/posix/octhread.o] Error 1
scons: building terminated because of errors.
➜ iotivity git:(master) ✗
I'm following the instructions at https://wiki.iotivity.org/macosx_build_instructions pointed to by https://wiki.iotivity.org/build_for_your_system
had a look but can't see any flags that'd enable mac support explicitly. Anyone know if this is actually supported and just been broken in recent commits? I building master checked out two days ago.
There is a windows-port branch but no mac named branches. remotes/origin/1.3-rel has the same issue.
Found this https://stackoverflow.com/a/24947106/400048 which lead me to my assertion about the posix specific headers being used.
So, anyone know if this can be built on mac and if so, how?
It's not an "officially supported" platform or target at this point, I gather its health was better in the past. Some people have had decent luck building for Mac, I have not. Changes to improve it will certainly considered, and there's an opening for a "Mac port maintainer" to make sure it doesn't rot again (and there's a github project which has added Mac buildability along with other build system reorgs - but I believe compared to iotivity that's rather out of date - however one could start picking fixes from there: https://github.com/OpenOCF/iochibity)