I am exploring Intel's librealsense library. Tracing the code, I can see that rs2_device_info is defined in rs_types.h as follows:
typedef struct rs2_device_info rs2_device_info;
However, it does not contain detailed the actual definition like rs2_intrinsics in the same file. Could someone show me where it is? How can the code compile if the actual definition is missing? Thanks.
The definition of rs2_device_info can be found in ./src/context.h.
Specifically it is defined as:
struct rs2_device_info
{
std::shared_ptr<librealsense::context> ctx;
std::shared_ptr<librealsense::device_info> info;
};
As a note, after you clone the repo and navigate to the directory you can run the command
grep -r . -e "struct rs2_device_info"
Related
I'm trying to port the lhslib library (written in C++) to WebAssembly using emscripten (emcc v. 1.40.1, clang v. 12.0.0, macOS 10.15.5). Unfortunately I have a very limited understanding of C++, so please bear with me.
So far, I forked the repo, created a build folder, and from there started to try and convert the randomLHS.cpp file to WASM:
// a short overview of what the file looks like
#include "LHSCommonDefines.h"
#include "utilityLHS.h"
namespace lhslib
{
void randomLHS(int n, int k, bclib::matrix<int> & result, bclib::CRandom<double> & oRandom)
{
// further contents of the file
}
}
Running
emcc ../src/lhslib/randomLHS.cpp -I../src/bclib -o randomLHS.html
creates the expected files randomLHS.wasm ,randomLHS.js, and randomLHS.html.
However, when serving the html file and inspecting the Module object created by emscripten, it does not contain the desired randomLHS function.
I then read about the EXPORTED_FUNCTIONS option and proceeded to try the following
emcc ../src/lhslib/randomLHS.cpp -I../src/bclib -o randomLHS.html -s EXPORTED_FUNCTIONS='["_randomLHS"]' -s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]'
This results in the following error:
emcc: error: undefined exported function: "_randomLHS" [-Wundefined] [-Werror]
Unfortunately I couldn't find any examples showcasing how to export a namespace (as in the randomLHS file), or how to specify a function from the namespace that should be exported.
Could you guide me on how I could achieve this?
Thanks for you help!
So according to the emscripten docs on using ccall and cwrap:
These methods can be used with compiled C functions — name-mangled C++ functions won’t work.
I believe there are other ways to do this; check out WebIDL Binder and Embind.
I am a beginner in CMake and I am trying to follow a tutorial for a project I am currently working on. The tutorial can be found here: https://gepettoweb.laas.fr/doc/stack-of-tasks/pinocchio/master/doxygen-html/index.html#OverviewInstall (Part: More complex example with C++ and Python).
At some point, this tutorial provides a g++ command for compilation, but because of the specifities of my project, I can't use the terminal and have to translate this command to a CMakeLists.txt. Here is the command:
g++ -I /path/to/eigen -I /path/to/pinocchio/include/ -DPINOCCHIO_URDFDOM_TYPEDEF_SHARED_PTR -DPINOCCHIO_WITH_URDFDOM overview-urdf.cpp -lboost_system -lurdfdom_model -o overview-urdf
My problem concerns the second part of the command, starting from the flags. I added my executable and the two first path, and then I wrote this:
target_compile_definitions(overview-urdf PUBLIC PINOCCHIO_URDFDOM_TYPEDEF_SHARED_PTR PINOCCHIO_WITH_URDFDOM)
target_link_libraries(overview-urdf /usr/lib/x86_64-linux-gnu/libboost_system.so)
target_link_libraries(overview-urdf /opt/ros/foxy/lib/liburdfdom_world.so)
But if I try to build everything, the compilation fails and indicates an error in a file from the Pinocchio library I use (a file that I did not modify and on which there is no git issue declared). The functions in which a problem is indicated seem to all be concerned by the PINOCCHIO_URDF_SHARED_PTR, thus I expect that there is a problem with how I inserted the flags in my CMakeLists.
I hope that it is clear enough. Thanks in advance!
EDIT: extract of the error message
In file included from /opt/openrobots/include/pinocchio/parsers/urdf.hpp:261:0,
from testPinocchio.cpp:1:
/opt/openrobots/include/pinocchio/parsers/urdf/geometry.hxx:256:7: error: template-id ‘getLinkGeometry<urdf::Collision>’ for ‘urdf::CollisionConstSharedPtr pinocchio::urdf::details::getLinkGeometry(urdf::LinkConstSharedPtr)’ does not match any template declaration
getLinkGeometry< ::urdf::Collision>(const ::urdf::LinkConstSharedPtr link)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/openrobots/include/pinocchio/parsers/urdf/geometry.hxx:252:7: note: candidate is: template<class T> boost::shared_ptr<const T> pinocchio::urdf::details::getLinkGeometry(urdf::LinkConstSharedPtr)
getLinkGeometry(const ::urdf::LinkConstSharedPtr link);
And here is the corresponding code extract; coming from the corresponding file on the git of Pinocchio:
template<typename T>
inline PINOCCHIO_URDF_SHARED_PTR(const T)
getLinkGeometry(const ::urdf::LinkConstSharedPtr link);
template<>
inline ::urdf::CollisionConstSharedPtr
getLinkGeometry< ::urdf::Collision>(const ::urdf::LinkConstSharedPtr link)
{
return link->collision;
}
template<>
inline ::urdf::VisualConstSharedPtr
getLinkGeometry< ::urdf::Visual>(const ::urdf::LinkConstSharedPtr link)
{
return link->visual;
}
Try:
add_executable(overview-urdf overview-urdf.cpp)
target_include_directories(overview-urdf PUBLIC
/path/to/eigen
/path/to/pinocchio/include/
)
target_compile_definitions(overview-urdf PUBLIC
PINOCCHIO_URDFDOM_TYPEDEF_SHARED_PTR
PINOCCHIO_WITH_URDFDOM
)
target_link_libraries(overview-urdf PUBLIC
boost_system
urdfdom_model
)
After trying the syntax proposed by KamilCuk, I got the same error. I managed to use the given g++ compilation command "artificially" in my architecture, and it led to the same error than before... Thus, I think that the error does not come from the CMakeLists itself.
I'm trying to compile/port an older version of OpenOffice. It uses Boost v1.34.1, which is part of the source tree. The error message is as follows:
Undefined symbols:
"boost::throw_exception(std::exception const&)", referenced from:
boost::detail::shared_count::shared_count<ScToken>(ScToken*)in detfunc.o
ld: symbol(s) not found
Boost is new to me, and I haven't been able to find much online to help me understand this. From the error message, I understand that I probably need to link a library. However, boost::throw_exception is defined in a header file with no matching library (that I can find). Just for kicks, I've tried #include <boost/throw_exception.hpp> in detfunc and using symbolic links to put the header file in the same directory with no luck.
Is there a library I should be linking with -l or an include path with -I? How should I get that symbol referenced in?
Boost expects the project either to be built with macro BOOST_NO_EXCEPTIONS undefined, or to define the function boost::throw_exception itself.
From <boost/throw_exception.hpp> in version 1.34.1:
namespace boost
{
#ifdef BOOST_NO_EXCEPTIONS
void throw_exception(std::exception const & e); // user defined
#else
//[Not user defined --Dynguss]
template<class E> inline void throw_exception(E const & e)
{
throw e;
}
#endif
} // namespace boost
Boost's configuration headers will determine whether to define the macro or not. It looks like it boils down to the compiler you're using, but there may be other factors. Take a look in the boost/config/compiler/ folder for the header file that corresponds to your compiler, then search for BOOST_NO_EXCEPTIONS in it. There should be some conditions around the #define to help explain when Boost defines it. You may be able to configure your build to avoid the definition and get past the linker error you're experiencing.
If you're unable to change your compiler config to avoid the definition, then you're probably left defining boost::throw_exception(std::exception const & e) yourself somewhere in the OpenOffice code. I'm unfamiliar with that code, though, so I can't give a good suggestion where it should go.
I'm trying to compile a simple HelloWorld Prgramm from C++ to Javascript using emscripten.
It works fine when I include a main function which call's e.g. the multi function.
Here is my code (HelloWorld.cpp).
#include <stdio.h>
class HelloWorld {
public: void sayHello() {
printf("Hello World Klasse! %f", multi(7));
}
public: double multi(double x){
return x * x;
}
};
However if I don't include a main function the emcc compile always put's out
ERROR root: No functions to process. Make sure you prevented LLVM
from eliminating them as dead (use EXPORTED_FUNCTIONS if necessary,
see the FAQ)
I know about the 'EXPORTED_FUNCTIONS' option which tells what functions should be included into the compile .js file.
I tried various diffrent things:
Using the mangling name, as far as I understood this the name should be '_multi_d10HelloWorldd'. I also tried without classname and some other combinations.
emcc -s HelloWorld.cpp -s EXPORTED_FUNCTIONS='["_multi_d10HelloWorldd"]'
Using the modifier EXPORT_ALL
emcc -s HelloWorld.cpp -s EXPORT_ALL=1
Whatever I do the functions won't be included in the final js file.
From what I understand from the EMCC FAQ I need to use EXPORTED_FUNCTIONS so I can later on call the desired function e.g. 'sayHello' from JS unsing the same method name.
And this is exactly what I need to do later on.
Could someone please point me to a solution or any other possible option which I may have not thought of ?
Is the mangling name I thought of correct ?
Create an "extern c" block. Inside this block define the functions you want to expose to javascript. These functions should be prefixed with an underscore. Inside one of these functions you can instantiate your C++ class.
This is the same approach as one would take when writing a dynamic library, which has the advantage that you can reuse your library in a native program should you wish.
I'm trying to write a binding for a vendor C++ library. I've successfully used snippets such as the below to define init functions in the other modules, but in this one it doesn't seem to work: it compiles fine, but throws the ImportError as soon as I try to import it into a test script. What could be wrong here?
#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
#define PyMODINIT_FUNC void
#endif
PyMODINIT_FUNC initclient(void) {
PyObject* m;
ClientType.tp_new = PyType_GenericNew;
if (PyType_Ready(&ClientType) < 0)
return;
m = Py_InitModule3("client", client_methods, "Client module");
Py_INCREF(&ClientType);
PyModule_AddObject(m, "Client", (PyObject *) &ClientType);
}
This is on 32-bit Linux, with gcc 4.4.4.
I had the same issue. At compile time:
path to the Python header: OK
path to the Python library: OK
link against the Python library: OK
link against needed third parties libraries/object files: OK
I just forgot to compile the C file that defines my module... Sigh...
So yeah, first thing to check: your makefile or your compilation command! :)
Make sure you don't mix Python versions. In Python version 2 the init function was called Init_, while in version 3 this function is called PyInit_
In my case this was happening when SWIG 3.0.2 used Python 3.4 to generate bindings, while my Python IDE called the Python 2.7 interpreter.
You can see the difference in the generated .cxx file:
#if PY_VERSION_HEX >= 0x03000000
# define SWIG_init PyInit__<modulename>
#else
# define SWIG_init init_<modulename>
#endif
On linux you can also use the following command to check your .so exports:
nm -D <modulename> | grep <modulename>
This will give you the name of the init function within your library.
I had the same error message, but it was because I renamed my .c file, and forgot to update the name inside the code. The "initxxx" function and an argument inside it.
Make sure you include your _wrap.cxx. It seems to me it doesn't get compiled into your module.
On linux it can help to run strace in this case. Check that the name of the library python is searching for is the same as the name of the library you built.
The swig documentation mentions here:
This error is almost always caused when a bad name is given to the shared object file. For example, if you created a file example.so instead of _example.so you would get this error.
In the interface file, SWIG suggests using:
#define SWIG_FILE_WITH_INIT
This turned to be unrelated to Python or the compiler, but was an incorrect compiler incantation (have to pay more attention while editing the Makefile).