Eclipse Environment setup using Protocol Buffers (Protobuf) - c++

Jetson Nano - Jetpack 4.5.1
G++ Version - 4.8
Protobuf Version - 3.0
I've been messing with a gstreamer framework and creating a custom plugin for it, and essentially I want to make a managing process as a gstreamer plugin to communicate to an SDK compiled through Eclipse. It's not my software and therefore I stick to following the environment setup and using eclipse to compile the executable.
I've added a single file where I am trying to extract data from the SDK, in the SDK, and want to use protobufs and zmq as the inter-process communication.
How I was able to get ZMQ to compile in Eclipse was by apt installing libczmq on the Jetson Nano and scp'd the .so binaries over to our host machine (amd64 architecture, I understand this was a workaround but I couldn't figure out how to cross compile it). The binaries are stored in a directory on the host machine and the paths are individually being added to the Eclipse Project Properties -> C/C++ Build -> Settings -> Tool Settings -> Cross G++ Linker -> Miscellaneous -> Other objects, since they are not in a normal .so format for Eclipse.
This solved all the ZeroMQ issues.
Protobuf has been a real issue. The best attempt was using a plugin called protobuf-dt which adds a menu to Eclipse for configuration to automatically generate the .pb.h and .pb.cc file from the given .proto file. The problem, I think, is it generates the files only using the connection to a descriptor.proto which is a location passed to the plugin as shown in the image below. Under /usr/include/google/protobuf/ there are multiple .proto files, not just the descriptor.proto, and we believe these are the missing connections that are causing undefined references to typeinfo for google::protobuf::Message or google::protobuf::internal::empty_string_ errors when invoking the G++ Linker.
I also tried manually adding the include path of where the google protobuf header/.proto files to the Project Properties -> C/C++ Build -> Settings -> Tool Settings -> Cross G++ Compiler -> Includes path. The last thing we tried was giving the Cross G++ Compiler the defined symbol of -D_GLIBCXX_USE_CXX11_ABI=0 for resolving C++11 ABI issues but that didn't seem to be the problem.
Any help on how to get protobuf to work with Eclipse for cross-compilation would be greatly appreciated.

Related

How to compile Quantlib via Xcode?

I am trying to install QuantLib on my Mac running OSX 10.11.6. Installed Boost 1.59 via MacPorts and then followed these instructions.
I used these additional environment variables
./configure --with-boost-include=/opt/local/include/ \
--with-boost-lib=/opt/local/lib/ --prefix=/opt/local/ \
CXXFLAGS='-O2 -stdlib=libstdc++ -mmacosx-version-min=10.6' \
LDFLAGS='-stdlib=libstdc++ -mmacosx-version-min=10.6'
and then make && sudo make install.
However when I run the Bermuda Swaption test it gave me the same error described here.
Little premise: I don't know anything about C++. I need QuantLib to work on Python. So I read carefully the answer by SmallChess and tried to solve it by myself. As I read in his answer
You can't just compile BermudanSwaption.cpp and hope everything would be fine. You have to compile the entire QuantLib library and link with the generated library files. Please google "compiling and linking C++" for more information.
By far, the easiest way to make it happen on Mac is to do it with Xcode. You will need to create a new Xcode project, and import the entire Quantlib project files into it. Next, you will need to create a main() function. Xcode does the compiling and linking for your automatically.
This is what I exactly did:
created a new project in Xcode (version 8.2.1)(file/new project/Command Line Tool/"HelloWorld"/Documents/create)
selected Targets, Build Phases and Link Binary With Library. Added libQuantLib.0.dylib
set libstdc++(GNUC++ standard library) as C++ Standard Library in Build Settings
Modified Header Search Paths to include: /opt/local/include/, and Library Search Paths to include: /opt/local/lib
C++ Language Dialect is set on Compiler Default.
Dragged the ql folder onto the left window of the Xcode
Now, I managed to copy a simple code which includes the library and even if there are many warnings, it runs. Still when I run on the Terminal the command for the Bermuda Swaption test I get the same error. What am I doing wrong?
Additional info (may or may not be useful): if I change the C++ Standard Library setting on Xcode to libc++, I get on Xcode the same error I get when i try the Bermuda Swaption test (ld: symbol(s) not found for architecture x86_64).
Any help would be very much appreciated
Regards
EDIT: you can find a picture of the code at https://i.stack.imgur.com/1zhjO.png

Can't add dynamic frameworks to Command Line Tool

Goals
I added Command Line Tool target to an iOS app and linked with swift frameworks. (tested with Realm and SwiftyJSON)
Expected Results
Build Command Line tool with those libraries.
Actual Results
Xcode output:
dyld: Library not loaded: #rpath/libswiftCore.dylib
Referenced from: .../Xcode/DerivedData/.../Build/Products/Debug/RealmSwift.framework/Versions/A/RealmSwift
Reason: Incompatible library version: RealmSwift requires version 1.0.0 or later, but libswiftCore.dylib provides version 0.0.0
Steps to Reproduce
Create empty Swift Command Line Tool and link Realm frameworks
Code Sample
CommandLineTest.zip
Version of Frameworks and Tooling
Realm version: github "realm/realm-cocoa" "master"
SwiftyJSON version: github "acegreen/SwiftyJSON" "swift3"
Xcode version: 8 GM (which is on the App Store)
Dependency manager + version: Carthage 0.18
Command-line tools are best with static archives because everything is distributed as a single binary. Looking at Realm, I don't see that there is a static archive option. They do have an iOS static framework that I got compiling for macOS but that's not quite what you want. You might want to try playing with Realm's source a bit more to see if you can get it to produce a static archive.
In the mean time, as a workaround, you'll need to tell Xcode where to find the dylibs at runtime and also to install them somewhere.
In your Build Settings, go down to "Runpath Search Paths" and add "#rpath".
In Build Phases, under Copy Files, click the + button and add both Realm.framework and RealmSwift.framework from your project.
Because Realm is compiled with an older version of Swift, you also need to specify "Use Legacy Swift Language Version" in Build Settings.
That will get your project building and finding the Realm libraries but now it will fail to find libswiftCore.dylib. That's because normally command-line tools are statically linked with the Swift library but as soon as you add a framework/dylib, the linker no longer includes the static version.
Go back to Build Phases, Copy Files, and add the following:
libswiftObjectiveC.dylib
libswiftIOKit.dylib
libswiftFoundation.dylib
libswiftDispatch.dylib
libswiftDarwin.dylib
libswiftCoreGraphics.dylib
libswiftCore.dylib
You can find them inside your Xcode installation and then ./Contents/Developer/Toolchains/Swift_2.3.xctoolchain/usr/lib/swift/macosx/
WARNING: Keep in mind that you will need to distribute the frameworks and the dylibs with your command-line tool and they will need to be in the same directory as the tool. You can put them somewhere else on the system by specifying a different runpath but you'll still need them distributed with your tool.
The nice thing about a .app bundle is that it gives you a place to put this stuff and users can just drag-and-drop it to install it. If you could get a static archive version of Realm, you could distribute everything in one binary.

Following a Lynda.com c++ tutorial and having problems setting up paths on Eclipse (OSX 10.9.3)

I am currently learning C++ using Lynda.com tutorials, I am a complete beginner and am following the tutorials on how to set up Eclipse on my Mac.
When I initially run the version-test.cpp program provided, it runs fine with the expected output (GCC version 4.2.1)
The tutorial requires my Mac to be running GCC version 4.7.0 or above and it explains how to upgrade GCC. The tutorial instructs me to save the updated GCC files within my home directory within the folder hpc-gcc and then follows on to explain the method to set my PATHs to find this folder.
Now when I run the version-test.cpp program it fails with the following error
dyld: Library not loaded: /usr/local/lib/libmpc.3.dylib
Referenced from: /Users/gary/hpc-gcc/bin/../libexec/gcc/x86_64-apple-darwin13.1.0/4.9.0/cc1plus
Reason: image not found
So from this message I can see that the system cannot find the required files within /usr/local/lib.
I am able to copy the files from hpc-gcc/bin to /usr/local/lib and have the program compile and run correctly but I am hoping to find out why Eclipse cannot read the required files directly from ~/hpc-gcc/bin
I have spent the last 2 hours searching forums and search engines for the answer but I am no further forward. I realise I can simply have the GCC files within /usr/local/lib and it will work but I want to understand where I am going wrong.
Solved.
You need to go into the properties of the Working folder (if you are following the lynda.com program you will understand the working folder) and under C/C++ Build -> Environment menu (Where we added in the LIBRARY_PATH, PATH, AND CPATH variables) and add in DYLD_LIBRARY_PATH with a value of ${HOME}/hpc-gcc/lib.
Remember the C/C++ Build "menus" are for build and debug, so the project is not able to find the library for the building process.
And you will be good to go.

How do I compile libnoise on Mac OS X Mountain Lio

I am new to the Mac OS X environment when it comes to compiling linux based libraries. Whenever I used a library i just downloaded the .framework file, added it to my /Library/Frameworks and included it in my XCODE project, and all was fine.
Now I am stuck with libnoise. I want to use it on my project and I have no idea how to generate the .framework file/directory.
Can you help me please?
If you have libnoise, most likely it contains some sort of a Makefile or a configure script.
By running the
./configure
make all
you will get the library file (libnoise.a) for your platform, the OSX10.8.
Framework is essentially a folder with specific layout and a .plist file. To generate such a folder automatically, you may create an expty Xcode project of the type Framework and add the libnoise.a you've just created as a linker's input.
There is a detailed instruction on how to create the Framework from static libraries (.a files): http://www.blackdogfoundry.com/blog/creating-a-library-to-be-shared-between-ios-and-mac-os-x/
You might be missing the header files in you framework, but then can be also added to the Xcode project from libnoise sources.
This SO answer may be of use also: Difference between framework and static library in xcode4, and how to call them
Apple's documentation is also good: https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html
I'm not entirely sure if this is what was meant by "with a different fork and cmake"
but I got libnoise to run in my mac using this git repo.
https://github.com/qknight/libnoise

Undefined reference to Eclipse C++

I've tried more and more time, but I got the same error.
When I use an external lib, for example I'm try to work on openssl and crypto++, I receive the error: "undefined reference to (function)".
I dunno why Eclipse do that neverthless the #include are all correct.
I've tried even to add the path from Properties-C/C++ General-Path & Symbols but nothing.
Can anybody help me?
You must specify the name of the shared libraries which must be linked to the executable.
Assuming you are using the GNU toolchain, you can do it by following these steps:
Right-click on the project, then select Properties
Go under C/C++ Build -> Settings
Select GCC C Linker -> Libraries
In Libraries (-l), add the name of your libraries,
If needed, put the directory where your libraries are hosted in Library search path (-L).
I have the same problem too. I was using Eclipse CDT and trying to build my source code with OpenSSL headers and I got the same "undefined reference" problem.
To those who may be also suffering from this type of errors, try these steps:
Make sure you use the right compiler(for Ubuntu 18.04)
right click your project->preference->C/C++ Build->tool chain editor->use CDT internal Builder / Linux gcc(you can try to run HelloWorld as a test)
C/C++ Build->settings->gcc linker, see right there is a "+", click and type ssl and crypto
Rebuild your project, done.
I strongly recommend you to learn gcc compiler command line. If you have compile problem, always use the terminal and command line to see if you can compile it successfully, then compare the succeeded command with the console log in Eclipse, at where you can see the actual gcc command that used to compile your code.
A good resource for gcc command: https://www.rapidtables.com/code/linux/gcc/gcc-l.html