C++ project with Objective-C++ framework import fails to build - c++

I have a CMake C++ project which targets mac, which has a .h header file that includes the following import.
#import <Foundation/Foundation.h>
When I try to build the project, I get the following compiler error:
In file included from /Users/ram/development/foo/mac/FooComponent.h:12:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:8:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:492:1: error: expected unqualified-id
#class NSString, Protocol;
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:503:50: error: unknown type name 'Protocol'
FOUNDATION_EXPORT NSString *NSStringFromProtocol(Protocol *proto) API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:504:19: error: unknown type name 'Protocol'
FOUNDATION_EXPORT Protocol * _Nullable NSProtocolFromString(NSString *namestr) API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:508:53: error: format argument not an NSString
FOUNDATION_EXPORT void NSLog(NSString *format, ...) NS_FORMAT_FUNCTION(1,2) NS_NO_TAIL_CALL;
~~~~~~~~~~~~~~~~ ^ ~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:94:49: note: expanded from macro 'NS_FORMAT_FUNCTION'
#define NS_FORMAT_FUNCTION(F,A) __attribute__((format(__NSString__, F, A)))
^ ~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:509:63: error: format argument not an NSString
FOUNDATION_EXPORT void NSLogv(NSString *format, va_list args) NS_FORMAT_FUNCTION(1,0) NS_NO_TAIL_CALL;
~~~~~~~~~~~~~~~~ ^ ~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:94:49: note: expanded from macro 'NS_FORMAT_FUNCTION'
#define NS_FORMAT_FUNCTION(F,A) __attribute__((format(__NSString__, F, A)))
^ ~
I've tried updating the project's CMakeLists.txt to pass `"-framework Foundation" but somehow CMake filters out that library from the build.
Does anyone know what might be the root cause, and how to fix it?

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.

Veins 4.7 Omnet++ 5.3 build error in windows 7

I am new to vein and omnet++. I followed this tutorial http://veins.car2x.org/tutorial/ everything works up to step 3, for some reason veins 4.7 doesn't build in omnet++ 5 (IDE) and generates the following errors.
veins/modules/utility/TimerManager.cc
In file included from veins/modules/utility/TimerManager.cc:20:
.\veins/modules/utility/TimerManager.h:137:26: error: expected identifier
enum class StartMode { RELATIVE, ABSOLUTE, IMMEDIATE };
^
C:\Users\Abu\src\omnetpp-5.3\tools\win64\mingw64\x86_64-w64-mingw32\include\wingdi.h:1434:18: note: expanded from macro 'RELATIVE'
#define RELATIVE 2
^
In file included from veins/modules/utility/TimerManager.cc:20:
.\veins/modules/utility/TimerManager.h:137:36: error: expected identifier
enum class StartMode { RELATIVE, ABSOLUTE, IMMEDIATE };
^
C:\Users\Abu\src\omnetpp-5.3\tools\win64\mingw64\x86_64-w64-mingw32\include\wingdi.h:1433:18: note: expanded from macro 'ABSOLUTE'
#define ABSOLUTE 1
^
In file included from veins/modules/utility/TimerManager.cc:20:
.\veins/modules/utility/TimerManager.h:138:24: error: expected identifier
enum class EndMode { RELATIVE, ABSOLUTE, REPITITION, OPEN };
^
C:\Users\Abu\src\omnetpp-5.3\tools\win64\mingw64\x86_64-w64-mingw32\include\wingdi.h:1434:18: note: expanded from macro 'RELATIVE'
#define RELATIVE 2
^
In file included from veins/modules/utility/TimerManager.cc:20:
.\veins/modules/utility/TimerManager.h:138:34: error: expected identifier
enum class EndMode { RELATIVE, ABSOLUTE, REPITITION, OPEN };
^
C:\Users\Abu\src\omnetpp-5.3\tools\win64\mingw64\x86_64-w64-mingw32\include\wingdi.h:1433:18: note: expanded from macro 'ABSOLUTE'
#define ABSOLUTE 1
^
veins/modules/utility/TimerManager.cc:42:28: error: expected unqualified-id
start_mode_ = StartMode::RELATIVE;
^
C:\Users\Abu\src\omnetpp-5.3\tools\win64\mingw64\x86_64-w64-mingw32\include\wingdi.h:1434:18: note: expanded from macro 'RELATIVE'
#define RELATIVE 2
^
veins/modules/utility/TimerManager.cc:48:28: error: expected unqualified-id
start_mode_ = StartMode::ABSOLUTE;
^
C:\Users\Abu\src\omnetpp-5.3\tools\win64\mingw64\x86_64-w64-mingw32\include\wingdi.h:1433:18: note: expanded from macro 'ABSOLUTE'
#define ABSOLUTE 1
^
veins/modules/utility/TimerManager.cc:54:24: error: expected unqualified-id
end_mode_ = EndMode::RELATIVE;
^
C:\Users\Abu\src\omnetpp-5.3\tools\win64\mingw64\x86_64-w64-mingw32\include\wingdi.h:1434:18: note: expanded from macro 'RELATIVE'
#define RELATIVE 2
^
veins/modules/utility/TimerManager.cc:60:24: error: expected unqualified-id
end_mode_ = EndMode::ABSOLUTE;
^
C:\Users\Abu\src\omnetpp-5.3\tools\win64\mingw64\x86_64-w64-mingw32\include\wingdi.h:1433:18: note: expanded from macro 'ABSOLUTE'
#define ABSOLUTE 1
^
veins/modules/utility/TimerManager.cc:86:19: error: expected unqualified-id
case StartMode::RELATIVE:
^
C:\Users\Abu\src\omnetpp-5.3\tools\win64\mingw64\x86_64-w64-mingw32\include\wingdi.h:1434:18: note: expanded from macro 'RELATIVE'
#define RELATIVE 2
^
veins/modules/utility/TimerManager.cc:88:30: error: expected unqualified-id
start_mode_ = StartMode::ABSOLUTE;
^
C:\Users\Abu\src\omnetpp-5.3\tools\win64\mingw64\x86_64-w64-mingw32\include\wingdi.h:1433:18: note: expanded from macro 'ABSOLUTE'
#define ABSOLUTE 1
^
veins/modules/utility/TimerManager.cc:90:19: error: expected unqualified-id
case StartMode::ABSOLUTE:
^
C:\Users\Abu\src\omnetpp-5.3\tools\win64\mingw64\x86_64-w64-mingw32\include\wingdi.h:1433:18: note: expanded from macro 'ABSOLUTE'
#define ABSOLUTE 1
^
veins/modules/utility/TimerManager.cc:98:17: error: expected unqualified-id
case EndMode::RELATIVE:
^
C:\Users\Abu\src\omnetpp-5.3\tools\win64\mingw64\x86_64-w64-mingw32\include\wingdi.h:1434:18: note: expanded from macro 'RELATIVE'
#define RELATIVE 2
^
veins/modules/utility/TimerManager.cc:100:26: error: expected unqualified-id
end_mode_ = EndMode::ABSOLUTE;
^
C:\Users\Abu\src\omnetpp-5.3\tools\win64\mingw64\x86_64-w64-mingw32\include\wingdi.h:1433:18: note: expanded from macro 'ABSOLUTE'
#define ABSOLUTE 1
^
veins/modules/utility/TimerManager.cc:102:17: error: expected unqualified-id
case EndMode::ABSOLUTE:
^
C:\Users\Abu\src\omnetpp-5.3\tools\win64\mingw64\x86_64-w64-mingw32\include\wingdi.h:1433:18: note: expanded from macro 'ABSOLUTE'
#define ABSOLUTE 1
^
veins/modules/utility/TimerManager.cc:106:26: error: expected unqualified-id
end_mode_ = EndMode::ABSOLUTE;
^
C:\Users\Abu\src\omnetpp-5.3\tools\win64\mingw64\x86_64-w64-mingw32\include\wingdi.h:1433:18: note: expanded from macro 'ABSOLUTE'
#define ABSOLUTE 1
^
15 errors generated.
make[1]: *** [Makefile:205: ../out/clang-debug/src/veins/modules/utility/TimerManager.o] Error 1
make[1]: Leaving directory '/c/Users/Abu/src/veins-4.7/src'
make: *** [Makefile:12: all] Error 2
I am also using sumo_win64_0.32.0. I am not sure what causes these errors.
Any help is greatly appreciated.
The issue has been fixed in this pull request and a new minor revision of Veins (i.e. Veins 4.7.1) has been released. Please download the new version to get the fix and also some additional improvements.
I just encountered that error as well and here is what happens:
The compiler cannot resolve the enum class definitions in TimerManager.h as there is a name ambiguity with the macros RELATIVE and ABSOLUTE within wingdi.h
enum class StartMode { RELATIVE, ABSOLUTE, IMMEDIATE };
enum class EndMode { RELATIVE, ABSOLUTE, REPITITION, OPEN };
Quick fix is to rename the occurrences in TimerManager.h and TimerManager.cc to something else. E.g. Replace all occurrences of RELATIVE with RELATIVEINS and ABSOLUTE with ABSOLUTEVEINS etc... (or whatever you like). Worked fine for me with 4.7 and OMNet++ 5.2.1.
A patch is required to make Veins 4.7 compile with OMNeT++ 5.3 for Windows. The cleanest way may be something like on https://pastebin.com/ymzqMpEF
- enum class StartMode { RELATIVE, ABSOLUTE, IMMEDIATE }
+ enum class StartMode { relative, absolute, immediate }
that is, renaming the all-uppercase enum class constants to lower case ones (something recommended by many coding styles as well).

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.

Errors while compiling DeSiNe

While I run make build for the project DeSiNe [Click to go to github page], I am getting the error ‘Topology’ does not name a type
$ make build
mkdir -m 755 -p obj/Algorithm
g++ -Wall -DNO_TIMER -DNO_TRACES -O3 -funroll-loops -finline-functions -fexpensive-optimizations -Isrc -o obj/Algorithm/Algorithm.o -c src/Algorithm/Algorithm.cpp
In file included from src/Network/TopologyFactory.h:21:0,
from src/Network/Topology.h:25,
from src/Network/Flow.h:20,
from src/Algorithm/Algorithm.h:20,
from src/Algorithm/Algorithm.cpp:14:
src/RandomVariables/RandomNumberGenerator.h: In member function ‘double RandomNumberGenerator::generate()’:
src/RandomVariables/RandomNumberGenerator.h:158:43: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
return (double) 2.0 - (*(float*) &itemp);
^
In file included from src/Network/Topology.h:25:0,
from src/Network/Flow.h:20,
from src/Algorithm/Algorithm.h:20,
from src/Algorithm/Algorithm.cpp:14:
src/Network/TopologyFactory.h: At global scope:
src/Network/TopologyFactory.h:76:5: error: ‘Topology’ does not name a type
Topology* create(const TString &description);
^
src/Network/TopologyFactory.h:84:48: error: ‘Topology’ has not been declared
void build(const NodePairDeque &nodepairs, Topology* topology);
^
src/Network/TopologyFactory.h:92:5: error: ‘Topology’ does not name a type
Topology* createTopologyAdjacency(const TString &description);
^
src/Network/TopologyFactory.h:103:5: error: ‘Topology’ does not name a type
Topology* createTopologyBarabasi(const TString &description);
^
src/Network/TopologyFactory.h:112:5: error: ‘Topology’ does not name a type
Topology* createTopologyErdos(const TString &description);
^
src/Network/TopologyFactory.h:120:5: error: ‘Topology’ does not name a type
Topology* createTopologyFile(const TString &description);
^
src/Network/TopologyFactory.h:129:5: error: ‘Topology’ does not name a type
Topology* createTopologyFull(const TString &description);
^
src/Network/TopologyFactory.h:138:5: error: ‘Topology’ does not name a type
Topology* createTopologyGrid2D(const TString &description);
^
src/Network/TopologyFactory.h:147:5: error: ‘Topology’ does not name a type
Topology* createTopologyRandom(const TString &description);
^
make: *** [Algorithm/Algorithm] Error 1
but the included Topology.h does contain
class Topology : public AbstractNetworkElement
{
// Friend(s)
How to resolve?
EDIT:
Adding forward declaration for class Topology gives further error:
In file included from src/Algorithm/SamcraBAlgorithm.h:22:0,
from src/Algorithm/SamcraBAlgorithm.cpp:17:
src/Utils/TString.h:25:7: error: using typedef-name ‘Types::TString’ after ‘class’
class TString
^
In file included from src/LinkStateUpdate/LinkStateUpdateVisitor.h:23:0,
from src/Network/Link.h:19,
from src/Network/Topology.h:23,
from src/Network/Flow.h:20,
from src/Algorithm/Algorithm.h:22,
from src/Algorithm/SamcraBAlgorithm.cpp:16:
src/Utils/Types.h:65:24: note: ‘Types::TString’ has a previous declaration here
typedef deque<string> TString;
^
make: *** [Algorithm/SamcraBAlgorithm] Error 1
Basically the project has four main compilation problems:
Circular include dependency between TopologyFactory and Topology classes.
Including TString.h header directly when is meant to be used as a typedef.
Missing cstdlib/cstdio includes.
Member initialization in class definition (not available until C++11).
The fix for the first one involves removing TopologyFactory from the Topology header, thus breaking the circular include dependency. Then including the TopologyFactory header where is needed.
The second one is easy to fix: just remove the TString header includes so it uses the definition at Utils/Types.h by default.
Third fix is trivial: just add the cstdio/cstdlib includes where needed.
The last fix involves moving the static initialization to the definition file (maybe the author was using an old compiler with an extension who allowed this type of initialization).
I made a patch on this gist so you can see the changes. The project compiles with g++ 5.2.1 on Ubuntu 15.10.
There is a cross-reference in the code.
Topology.h includes TopologyFactory.h and vice versa TopologyFactory.h included Topology.h
The most easy way to fix it add forward declaration for class Topology into TopologyFactory.h:
#ifndef TOPOLOGYFACTORY_H
#define TOPOLOGYFACTORY_H
...
class Topology;
class TopologyFactory
{
More correct approach would be try to solve these dependencies, i.e. don't include TopologyNetwork.h in Topology.h and then in all cpp files which using TopologyNetwork and Topology add two include directives:
/*
source file DesineModel.cpp for class: DesineModel
...
*/
...
#include "Network/Topology.h"
#include "Network/TopologyFactory.h"
...

Building C++ application with pre-build library gives compile errors

I am trying to modify a C++ program by including POCO to be able to do a HTTP request and receive a result. Basically, I just need within another C++ program to give a username and password and get a plain "OK" or "ERROR" response.
I am not familiar with C++ at all (use Java mainly). I build the POCO project and installed it without any problems, but when I add it to the project I get a while pile of compiler errors when building:
In file included from ../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:30:
In file included from /usr/local/include/Poco/Net/HTTPClientSession.h:44:
In file included from /usr/local/include/Poco/Net/HTTPSession.h:44:
In file included from /usr/local/include/Poco/Net/StreamSocket.h:44:
In file included from /usr/local/include/Poco/Net/Socket.h:44:
In file included from /usr/local/include/Poco/Net/SocketImpl.h:47:
In file included from /usr/local/include/Poco/Timespan.h:44:
/usr/local/include/Poco/Timestamp.h:50:1: error: declaration of anonymous class must be a definition
class Foundation_API Timestamp
^
/usr/local/include/Poco/Timestamp.h:149:24: error: expected identifier
inline bool Timestamp::operator == (const Timestamp& ts) const
^
/usr/local/include/Poco/Timestamp.h:149:13: error: declaration of anonymous struct must be a definition
inline bool Timestamp::operator == (const Timestamp& ts) const
^
../crtmpserver/sources/common/include/platform/osx/osxplatform.h:109:19: note: expanded from macro 'Timestamp'
#define Timestamp struct tm
^
In file included from ../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:30:
In file included from /usr/local/include/Poco/Net/HTTPClientSession.h:44:
In file included from /usr/local/include/Poco/Net/HTTPSession.h:44:
In file included from /usr/local/include/Poco/Net/StreamSocket.h:44:
In file included from /usr/local/include/Poco/Net/Socket.h:44:
In file included from /usr/local/include/Poco/Net/SocketImpl.h:47:
In file included from /usr/local/include/Poco/Timespan.h:44:
/usr/local/include/Poco/Timestamp.h:262:1: error: expected unqualified-id
} // namespace Poco
^
In file included from ../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:30:
In file included from /usr/local/include/Poco/Net/HTTPClientSession.h:44:
In file included from /usr/local/include/Poco/Net/HTTPSession.h:44:
In file included from /usr/local/include/Poco/Net/StreamSocket.h:44:
In file included from /usr/local/include/Poco/Net/Socket.h:44:
In file included from /usr/local/include/Poco/Net/SocketImpl.h:47:
/usr/local/include/Poco/Timespan.h:54:21: error: no struct named 'TimeDiff' in 'tm'
typedef Timestamp::TimeDiff TimeDiff;
~~~~~~~~~~~^
In file included from ../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:30:
In file included from /usr/local/include/Poco/Net/HTTPClientSession.h:44:
In file included from /usr/local/include/Poco/Net/HTTPSession.h:47:
/usr/local/include/Poco/Any.h:123:46: error: cannot use typeid with -fno-rtti
return _content ? _content->type() : typeid(void);
^
/usr/local/include/Poco/Any.h:149:20: error: cannot use typeid with -fno-rtti
return typeid(ValueType);
^
/usr/local/include/Poco/Any.h:180:42: error: cannot use typeid with -fno-rtti
return operand && operand->type() == typeid(ValueType)
^
In file included from ../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:30:
/usr/local/include/Poco/Net/HTTPClientSession.h:291:8: error: expected member name or ';' after declaration specifiers
Poco::Timestamp _lastRequest;
~~~~ ^
../crtmpserver/sources/common/include/platform/osx/osxplatform.h:109:19: note: expanded from macro 'Timestamp'
#define Timestamp struct tm
^
../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:94:10: error: expected expression
form.add(<D2>entry1<D3>, <D2>value1<D3>);
^
../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:97:25: error: variable has incomplete type 'Poco::Net::HTTPResponse'
Poco::Net::HTTPResponse response;
^
/usr/local/include/Poco/Net/HTTPClientSession.h:55:7: note: forward declaration of 'Poco::Net::HTTPResponse'
class HTTPResponse;
^
../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:99:41: error: no member named 'cout' in namespace 'std'; did you mean 'count'?
Poco::StreamCopier::copyStream(rs, std::cout);
~~~~~^~~~
count
/usr/include/c++/4.2.1/bits/stl_algo.h:424:5: note: 'count' declared here
count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
^
../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:99:36: error: address of overloaded function 'count' does not match required type 'std::basic_ostream<char>'
Poco::StreamCopier::copyStream(rs, std::cout);
^~~~~~~~~
/usr/include/c++/4.2.1/bits/stl_algo.h:424:5: note: candidate function
count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
^
/usr/local/include/Poco/StreamCopier.h:57:73: note: passing argument to parameter 'ostr' here
static std::streamsize copyStream(std::istream& istr, std::ostream& ostr, std::size_t bufferSize = 8192);
^
13 errors generated.
make[2]: *** [applications/idomsconnector/CMakeFiles/idomsconnector.dir/Users/[...]/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp.o] Error 1
make[1]: *** [applications/idomsconnector/CMakeFiles/idomsconnector.dir/all] Error 2
make: *** [all] Error 2
build failed
My code fragment is as follows:
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTMLForm.h>
#include <Poco/StreamCopier.h>
string RTMPAppProtocolHandler::GetAuthPassword(string user) {
INFO("Testing auth: %s", STR(user));
Poco::Net::HTTPClientSession s("www.somehost.com");
//s.setProxy("localhost", srv.port());
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/large");
Poco::Net::HTMLForm form;
form.add(“entry1”, “value1”);
form.prepareSubmit(request);
s.sendRequest(request);
Poco::Net::HTTPResponse response;
std::istream& rs = s.receiveResponse(response);
Poco::StreamCopier::copyStream(rs, std::cout);
return user;
}
Am I doing something stupid? It is only this little interaction with a HTTP server which I need to modify, so I am just looking for a very simple solution but find it hard to find something that works easy (mainly because I am not familiar with C++ though)