mdaus / nitro

NITRO (NITFio, "R" is a ligature for "Fi") is a full-fledged, extensible library solution for reading and writing the National Imagery Transmission Format (NITF), a U.S. DoD standard format. It is written in cross-platform C, with bindings available for other languages.
GNU Lesser General Public License v3.0
62 stars 37 forks source link

Compiling a C++ app with NITRO #32

Closed swarn closed 7 years ago

swarn commented 7 years ago

I can build, for example, show_nitf.c from the command line:

gcc show_nitf.c -lnitf-c -lnrt-c -ldl

But trying something similar for show_nitf++.cpp:

g++ show_nitf++.cpp -lnitf-c++ -lnrt-c++ -ldl

Results in:

In file included from /home/user/src/nitro/nitro-NITRO-2.7/installed/include/nitf/Object.hpp:26:0,
                 from /home/user/src/nitro/nitro-NITRO-2.7/installed/include/nitf/LookupTable.hpp:30,
                 from /home/user/src/nitro/nitro-NITRO-2.7/installed/include/nitf/BandInfo.hpp:28,
                 from /home/user/src/nitro/nitro-NITRO-2.7/installed/include/import/nitf.hpp:26,
                 from show_nitf++.cpp:23:
/home/user/src/nitro/nitro-NITRO-2.7/installed/include/nitf/Handle.hpp:71:17: error: ‘Mutex’ in namespace ‘sys’ does not name a type
     static sys::Mutex mutex;

I'm probably missing something...

asylvest commented 7 years ago

Yes, you want to build everything through waf rather than using gcc directly:

./waf configure --prefix=install
./waf install

(Or, if you want to build just show_nitf and show_nitf++, the second line can be used to target them directly:

./waf install --target=show_nitf,show_nitf++
swarn commented 7 years ago

Sorry, I was unclear. I was just using show_nitf as an example. I built NITRO as per the instructions:

$ python waf configure --alltests --enable-64bit --disable-swig --disable-java --disable-python --disable-matlab --prefix=installed
$ python waf build
$ python waf install

Both show_nitf and show_nitf++ compiled successfully and were copied to the bin directory.

Now, I have my own C++ code that I want to compile and link to NITRO. I copied show_nitf++.cpp from the NITRO source directory to another directory as a "known good" file so that I could attempt to build it before trying the same with my code.

asylvest commented 7 years ago

Ahh gotcha. So, two things:

  1. The error you're getting makes it sound like it's not finding the sys_config.h file (and so sys/Mutex.h isn't finding the ifdef it's looking for). You're reporting above you configured (which is when sys_config.h gets generated)... make sure that header is in your installed/include/sys directory.
  2. Use waf dumplib --target=show_nitf++ to get a list of all the required libraries to link in (though this doesn't seem to be your issue or you'd get a linker error... although above it doesn't look like you're linking in sys-c++ so you'd get one eventually).

Documentation on this site is sparse but SIX, which is another open source library we provide that's built on top of NITRO, is also built the same way and has a manual with some helpful build tips in it: https://github.com/ngageoint/six-library/blob/master/docs/six-manual.pdf.

Let me know if you still need a hand getting this working though.

swarn commented 7 years ago

Many thanks, @asylvest.

When I saw that I had no sys_config.h, I got the notion that maybe I should clone the latest version, rather than using the latest tagged version (2.7), which I now see is older than I realized. Mea culpa!

With new NITRO source and the info from waf dumplib, I write this:

g++ show_nitf++.cpp -lnitf-c++.2.7 -lmt-c++.1.1 -lio-c++.1.0 -lsys-c++.1.2 -lstr-c++.1.0 -lexcept-c++.1.0 -lnitf-c.2.7 -lnrt-c.2.7 -ldl -lrt -lm

Everything compiles and runs perfectly. I'll read the SIX docs for further info.

asylvest commented 7 years ago

OK great - glad you got this working. Ahh yes, I hadn't thought of this... In 2.7, we weren't generating the config.h files like we are now (you needed to set the proper defines yourself if you were building outside of waf... this led to a lot of confused users seeing the kinds of things you ran into :o) ).