How to add an project about idl on redhawk - c++

When I add an idl project in redhawk following the steps below:
$ ./reconf
$ ./configure
$ sudo make
$ sudo make install
I can find the newly added idl file in the REDHAWK Target SDR directory.
REDHAWK Target SDR
When testing whether the idl file can be called, I have added the header file and have already called the function interface, but at compile time, the error is: undefined reference to 'xxxxxxxx'
eg:
#include <redhawk/XH_IDL_TEST/xh_idl_test.h>
class data_t_test_base : public Component, protected ThreadedComponent
{
public:
data_t_test_base(const char *uuid, const char *label);
~data_t_test_base();
void start() throw (CF::Resource::StartError, CORBA::SystemException);
void stop() throw (CF::Resource::StopError, CORBA::SystemException);
void releaseObject() throw (CF::LifeCycle::ReleaseError,CORBA::SystemException);
void loadProperties();
protected:
xh_idl_test::_objref_dataChar *XH;
private:
}
errors:
/home/sca/sca_com/data_t_test/cpp/data_t_test.cpp:21: undefined reference to `xh_idl_test::_objref_dataChar::pushPacket()'
May I ask how to solve this problem?

In REDHAWK, IDL is accessed through ports, either uses (output) or provides (input). Once the IDL project is installed in your system, on component add a Port. Edit the port's interface by clicking on "Browse...". On the "Select and interface" menu, click "Show all interfaces", and then select the interface you want.
In the case of either input or output ports, the appropriate stubs will be generated.

Related

Eclipse Neon build errors despite successful build

I'm trying to use Eclipse to do the development for a project that involves Gazebo (a popular robotics simulator). Gazebo provides a plugin system to allow external interaction with the simulator and a series of tutorials on how to write plugins.
Having followed the tutorials successfully, I tried migrating the code to Eclipse, using cmake -G "Eclipse CDT4 - Unix Makefiles" [buildpath] to generate an eclipse rpoject, then importing it into my Eclipse workspace.
Everything generally went well, but I've run into a problem that is a bit odd:
When I compile my project, Eclipse comes back with "Member declaration not found" error referring to an SDFormat data type used in the signature to the ModelPush::Load function (see code snippets below). SDFormat, incidnetally is a robotics XML used for describing how a robot is put together.
Despite this error (which should result in nothing being built), the resulting shared library is built anyway.
I guess I can live with it, but I'd obviously like to resolve this issue, which appears to be internal to Eclipse / CDT...
TO CLARIFY:
I'm trying to determine why Eclipse gives me the error: "Member declaration not found" on the Load() function signature in model_push.cc. The guilty party is the sdf::ElementPtr _sdf parameter. Something's wrong with the SDFormat library or with the way that Eclipse / CDT looks at it. This isn't an include issue. And, even though Eclipse gives me the error, it still builds the .so file. Running make from the command line also generates the file, but without any errors.
Again, I can live with it, but I'd rather not. I just don't know where to start looking for a solution since this isn't a problem finding an include or the sdf library file.
Here's the class declaration (mode_push.hh):
#ifndef MODEL_PUSH_HH_
#define MODEL_PUSH_HH_
#include <boost/bind.hpp>
#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>
#include <gazebo/common/common.hh>
#include <stdio.h>
#include <sdf/sdf.hh>
namespace gazebo
{
class ModelPush : public ModelPlugin
{
public:
void Load (physics::ModelPtr _parent, sdf::ElementPtr _sdf);
//Called by the world update start event
void OnUpdate (const common::UpdateInfo & /*_info*/);
//Pointer to the model
private:
physics::ModelPtr model;
//Pointer to the update event connection
private:
event::ConnectionPtr updateConnection;
};
}
#endif /* MODEL_PUSH_HH_ */
Here's the implementation file (model_push.cc):
#include "model_push.hh"
namespace gazebo
{
void ModelPush::Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
//void ModelPush::Load (physics::ModelPtr _parent, sdf::ElementPtr /*sdf*/)
{
//Store the pointer to the model
this -> model = _parent;
//Listen to the update event. This event is broadcast every
//simulation iteration.
this -> updateConnection = event::Events::ConnectWorldUpdateBegin(
boost::bind (&ModelPush::OnUpdate, this, _1));
}
//Called by the world update start event
void ModelPush::OnUpdate (const common::UpdateInfo & /*_info*/)
{
//Apply a small linear velocity to the model.
this -> model -> SetLinearVel (math::Vector3 (0.03, 0.0, 0.0));
}
//Register this plugin with the simulator
//GZ_REGISTER_MODEL_PLUGIN(ModelPush)
}
I've been struggling with this exact problem. I've found a solution that works, but I still don't think is ideal. Instead of generating the eclipse project using cmake (or catkin_make) I'm generating it using the CDT project builder. Here's the process I'm using in Eclipse 2018-09.
Create a New C/C++ Project of type C++ Managed Build (A C++ Project build using the CDT's managed build system.)
Project name: ROSWorkspace
Location: /home/username/eclipse-workspace/ROSWorkspace
Project type: Makefile project / Empty Project
Toolchain: Linux GCC
Finish.
Right click on the project and select Properties.
C/C++ Build / Builder Stetings:
Uncheck "Use default build command"
Build command: catkin_make
Build directory: ${workspace_loc:/../catkin_ws}/
C/C++ General / Paths and Symbols / Includes tab
Add /usr/include/gazebo-8
Add /usr/include/sdformat-5.3
C/C++ General / Preprocessor Includes / Providers tab
CDT GCC Built-in Compiler Settings / Command to get compiler specs: ${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}" -std=c++11
Click Ok, then from the drop down menu choose:
Project / C/C++ Index / Freshen all files
Ideally I'd make the time to dig in to figure out how to get the preprocessor to properly work with the generated project, but I just don't have the time right now. I hope this helps.

Writing custom checkers for Clang Static Analyzer

I've just finished following the "Getting Started" instructions from the clang analyzer page.
My XCode is currently using the checker build 278
Right now I'm trying to follow some guides I can find to write my own custom checkers like
http://blog.trailofbits.com/2014/04/27/using-static-analysis-and-clang-to-find-heartbleed/
http://bbannier.github.io/blog/2015/05/02/Writing-a-basic-clang-static-analysis-check.html
Was hoping that someone can point me in the right direction and I'm not very familiar with building clang projects.
Are there any IDE available that would help?
How should I add the custom checker I wrote to the build 278?
I have recently started using clang checker's and here's how I got my custom checker to work with clang.
You have to modify the Checkers.td to register your checker.
<path-to-llvm>/llvm/tools/clang/lib/StaticAnalyzer/Checkers/Checkers.td
I made a debug checker to I put it under debug group and added these lines:
def MyCustomChecker : Checker<"DebugUsingMyChecker">,
HelpText<"Print results of my custom checker">,
DescFile<"DebugCheckers.cpp">; //this is the file where we define the class file of our checker
Then edit the DebugCheckers.cpp to add your checker's class to be invoked by the newly registered checker.
<path-to-llvm>/llvm/tools/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
And add under debug checkers tag
namespace
{
class MyCustomChecker : public Checker<check::ASTCodeBody> {
public:
void checkASTCodeBody(const Decl *D, AnalysisManager& mgr,
BugReporter &BR) const {
if (MyCustomChecker* CC = mgr.getAnalysis<CustomChecker>(D)) {
CC->dump(mgr.getSourceManager());
}
}
};
}
void ento::registerMyCustomChecker(CheckerManager &mgr) {
mgr.registerChecker<MyCustomChecker>();
}
After this, you can place the relevant class files in the folder:
<path-to-llvm>/llvm/tools/clang/lib/Analysis/
And edit the CMakeList.txt in that folder to include your class file.
Hope that clarifies the process. You can also read this link for more: http://clang-analyzer.llvm.org/checker_dev_manual.html
As far as IDE's are concerned, you can use any IDE which supports's CMake based projects (like CLion). You can look at this link for more: http://llvm.org/docs/CMake.html

Adding XCTest unit tests to existing app doesn't work

I've added tests (XCTests) to an existing C++ command line app in Xcode 5
via Test Navigator > (+),
changed the extension of the test class to .mm,
added the XCTest framework to the project.
All compiles fine. Now running the tests just gives me a 'Test failed' message, nothing in the console and neither green nor red lights in the Navigator (i.e. no tests executed).
Starting with a fresh Xcode 5 project and changing the extension of the test class to .mm just works fine so I'd assume it's not just about lacking support for Objective-C++ in XCTest.
Even with a plain, vanilla test target added to the existing C++ project the tests fail before ever running.
Any more gotchas to watch out for when adding XCTests to existing (Objective-)C++ targets?
Update #1
With Xcode 5.0.2 (on 10.8.5) xctest now crashes in the same scenario with an
*** NSTask: Task create for path '/Users/XXX/Library/Developer/Xcode/DerivedData/RM_Next_Gen-gpihzjouhxvifqcslmywktktizer/Build/Products/Debug/YYY Tests.xctest/Contents/MacOS/YYY Tests' failed: 22, "Invalid argument". Terminating temporary process.
objc[3478]: GC: forcing GC OFF because OBJC_DISABLE_GC is set
*** multi-threaded process forked ***
Turns out it was a command line C++ project which apparently isn't currently supported by XCTest. Testing the C++ code from an Objective-C(++) project works just fine..
Just hoping for better documentation of XCTest at some point in the (near) future.
I couldn't find any documentation on using XCTest to test code that is not Objective C (C / C++). I am wanting to test a command line C project, and I was concerned that your answer suggested that doing this is unsupported by Xcode. I'm a novice to XCTest and TDD, but I thought others might appreciate what I discovered.
I created a New Project > Command Line Tool, based on C. Project is called foo; Xcode will call the target foo by default too.
-Files created: main.c
Add test target by going to Test Navigator > (+) > New Test Target. Call the target fooTests. Xcode will create this target and an example test within it (all within the file called fooTests.m). The example test will be called testExample and it will contain the test function below:
- (void)testExample
{
XCTFail(#"No implementation for \"%s\"", __PRETTY_FUNCTION__);
}
If you run the tests now (either from the Product>Test menu item or ⌘U) then the test will fail (it's supposed to). For the sake of brevity, I won't go through the TDD cycle, but simply list the files and contents that need to be added to test functions that are not within Objective-C classes.
Let's say that we have a function that we want to test, called bar(), and called from main.c. Go to the project file explorer and add a new header file called bar.h. Add the function prototype:
int bar();
If you want to use XCTest to test a function, it can't be in main.c, so add it to a new C Source file called bar.c. Important: when you add the file, you must add it to the target foo and to fooTests. if you don't add it to fooTests then when compiling the tests the linker won't find the function.
int bar() {
return 0;
}
Within fooTests.m, add the include:
#include "bar.h"
You can now refer to any function contained in bar.h within your tests. Now create 2 unit tests, one that will fail, the other that will pass.
Delete the method testExample and replace with the following code:
- (void)testBarWillFail
{
int rc = bar();
XCTAssertTrue(rc == -1, #"Expected rc==-1, rc==%d", rc);
}
- (void)testBarWillPass
{
int rc = bar();
XCTAssertTrue(rc == 0, #"Expected rc==0, rc==%d", rc);
}
Running the tests will produce the following in the debug window:
Test Suite 'All tests' finished at 2014-01-12 13:38:45 +0000.
Executed 2 tests, with 1 failure (0 unexpected) in 0.000
Within the Issue Navigator pane you'll see:
file: /foo/fooTests/fooTests.m: test failure: -[fooTests testBarWillFail] failed: ((rc == -1) is true) failed - Expected rc==-1, rc==0
This is all as expected! Repeat the process with all other C code you wish to test.
If anyone knows a better way of doing this then I'd be delighted to hear it!

"windows cannot access the specified device....." error in c++

I am MFC guy working on visual studio 2010 create some executables using visual studio!! but on linux and mac my executables are not working as usual windows!!.
So i decided to use "MinGW" compiler to create executables.
Note:-Please give me one suggestion is that," is minGW is best compiler for cross plateform working ??or any thing else is there??"
I successfully install WinGW compiler on my C drive and start working with following program..
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello ";
return 0;
}
I compile it using following command,
g++ -static-libgcc -static-libstdc++ Main.cpp
I found one executable in same folder with name a.exe :).Working fine:)
But after some time i decide to modified same program in following manner like,
int main ()
{
return 0;
}
I compile it with same command but when i execute it using command line it show me error "Access is denied so i goto that folder and run same executable as "Run as Administrator" it show me one messagebox with the message windows cannot access the specified device path or file. you may not have appropriate permissions
---EDIT--
follwing code is NOT WORKING:-
int main ()
{
int k;
return 0;
}
but this program WORKING :-
int main()
{
int k;
k = 0;
return 0;
}
If you are getting this access denied error, then the most likely cause is that the executable file is open in another process, probably the linker or debugger. Try installing Process Explorer and hit Ctrl+F and type in the name of your .exe. This should show the processes that the .exe file open. Kill those processes (or if you are still debugging, then end debugging first). You then should be able to build again.
Note that this has nothing to do with Microsoft APIs, as in any case you're using gcc.
EDIT: If there are no processes holding the .exe then it may be that there is some other kind of permission problem. Does the .exe file exist? Can you delete the file and rebuild? Another thing to try is run Process Monitor and filter for the name of the .exe -- that may show a regular permission denied error, or perhaps another error such as a sharing conflict.
Note:-Please give me one suggestion is that," is minGW is best compiler for cross plateform working ??or any thing else is there??"
No. And there's nothing else out there.
Use whatever compiler is available on target platform, ensure your code compiles on all of them.
Avoid platform-specific and compiler-specific code at all costs (use cross-platform frameworks).
I successfully install WinGW
There are many different versions of mingw provided by different sites. If you install compiler from mingw.org using mingw-get, it'll probably work. If you install mingw from some other site, it may or may not work.
I compile it using following command,
Use a build systems. cmake, qmake or something similar.
it show me error "Access is denied
Launch process monitor and see after which system call it terminates. It is also possible that your antivirus software interferes with your program, or maybe there's some stray dll in your path or something like that.
Check the permissions for the entire folder in which the executable resides. Trying to 'Run as Administrator' doesn't have any effect if the folder doesn't allow the permissions.
It doesn't have anything to do with your code. This is an environmental problem, something is pretty messed up about the permissions your user account has for one or more of the directories on your hard disk. The generic diagnostic is that the default working directory for the program does not permit read or list access.
A possible starting point would be to use Explorer and right-click the directory where MinGW is installed. Use the Security tab and ensure that your user account has all permissions enabled. Further narrow it down to trying to run the program from the command prompt, using different directories as the default directory.

Boost.Extension - simple inheritance sample - why we see no animals on linux?

So I try to port some Boost.Extension samples for linux.
The sample is described here. Here is my code port (classes with animals, animal prototype, main app, general all port idea is described here, and some current linux progress here (some samples really work as needed!)). When I compile this sample under linux it compiles, it finds library with animals but outputs:
Animals not found!
Which shall happen only if(factories.empty()).
I try to port Extension samples onto crossplatform base - so I have tried same code under windows - works like a charm! finds all animals and outputs:
Creating an animal using factory:
Cougar factory Created an animal:
cougar Age: 2 Creating an animal using
factory: Leopard factory Created an
animal: leopard Age: 3 Creating an
animal using factory: Puma factory
Created an animal: puma Age: 4
Creating an animal using factory:
Wildcat factory Created an animal:
wildcat Age: 5
So... Why it behaves so on linux with same code? Why it works so well under Windows?
Update:
So how to build this stuff with premake:
You get svn from here (only this folder is required)
You get premake for your platform or build it from source and put it into folder you downloaded from svn
You should have official Boost compiled and installed (please read ReadMe.txt file we provide in directory) so what is needed:
Boost C++ library's (we tested with version 1.4.16)
Boost-Extension ( we use latest revision , we adress it as part of boost 'boost/extension/**' We had to make some chandes (actually only one) to boost extension so we provide it inside Boost.Extension.Tutorial/libs/boost/extension/ folder so when you downloaded svn you got it, it is header only )
Boost-Reflection ( we use it because of this tutorial , we use latest revision , we adress it as part of boost 'boost/reflection/**' *and for simplness we recommend just to put it into Boost.Extension.Tutorial/libs/boost/reflection * )
Now when official Boost is in your system, header only Boost-reflection and Boost-extension are in Boost.Extension.Tutorial/libs/boost folder, premake4 executable is inside Boost.Extension.Tutorial/ folder we can simply call Boost.Extension.Tutorial/ premake4-build-windows.bat on windows to get sln for Visual Studio or Boost.Extension.Tutorial/ premake-build.sh to get makefiles.
You can find generated solution/makefiles inside generated projects folder.
Have good luck!=)
Update 2:
Project files for Windows and Linux are now in svn so you can get aroung project creation with premake - just have Boost, our svn, and reflection headers only lib.
I debugged things on linux, good news:
You are running into bullet no. 3 from Jeremy Pack's post:
RTTI does not always function as expected across DLL boundaries. Check out the type_info classes to see how I deal with that.
I have a tiny workaround patch (below) to boost/extension/impl/typeinfo.hpp (but you need to talk to the maintainer of Boost Extension, really). What this does is not rely on builtin comparison for RTTI typeinfo's.
Looking at typeinfo.hpp, it seems that Windows never actually uses the typeinfo comparison, so I decided to test with the 'strcmp' fallback method, and voila:
$ LD_LIBRARY_PATH=. ./Simple-Inheritance
Creating an animal using factory: Cougar factory
Created an animal: cougar Age: 2
Creating an animal using factory: Leopard factory
Created an animal: leopard Age: 3
Creating an animal using factory: Puma factory
Created an animal: puma Age: 4
Creating an animal using factory: Wildcat factory
Created an animal: wildcat Age: 5
In particular, I can show that the type lookup from convertible_ fails at type_map.hpp, line 68;
When this conversion is called from the extension dll itself, the conversion happily finds the match using RTTI.
However, when the 'same' .get() is done from the test application (across DLL boundaries, i.e.) the RTTI is different and no such match is found, and line 74/75 are hit:
.
73 if (it == instances_.end()) {
74 holder = new type_holder<StoredType>;
75 it = instances_.insert(std::make_pair(t, holder)).first;
76 }
Patch
diff --git a/Boost.Extension.Tutorial/libs/boost/extension/impl/typeinfo.hpp b/Boost.Extension.Tutorial/libs/boost/extension/impl/typeinfo.hpp
index 843fed2..09fc353 100644
--- a/Boost.Extension.Tutorial/libs/boost/extension/impl/typeinfo.hpp
+++ b/Boost.Extension.Tutorial/libs/boost/extension/impl/typeinfo.hpp
## -50,7 +50,7 ## struct type_info_handler<default_type_info, ClassType>
// This list should be expanded to all platforms that successfully
// compare type_info across shared library boundaries.
-#if defined(__APPLE__) || defined(__GNUC__) || \
+#if defined(__APPLE__) || \
defined(BOOST_EXTENSION_FORCE_FAST_TYPEINFO)
namespace boost {
namespace extensions {
## -90,7 +90,7 ## inline bool operator>(const default_type_info& first,
} // namespace extensions
} // namespace boost
#else // OTHER OS
-#include <string>
+#include <cstring>
namespace boost { namespace extensions {
inline bool operator<(const default_type_info& first,
const default_type_info& second) {
GCC on Linux by default has stricter linker optimization settings that MSVC on Windows. This leads to some factory patterns where classes register themselves as available appearing broken, simply because the linker optimizes away the classes. I didn't look at your code - but from the description it could be the problem.
A related question, with an answer on how to avoid the unreferenced classes being dropped: How to force gcc to link unreferenced, static C++ objects from a library