Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building UDUNITS2 with CMAKE: missing EXPAT_INCLUDE_DIR #18

Closed
rsignell-usgs opened this issue Aug 18, 2014 · 35 comments
Closed

Building UDUNITS2 with CMAKE: missing EXPAT_INCLUDE_DIR #18

rsignell-usgs opened this issue Aug 18, 2014 · 35 comments

Comments

@rsignell-usgs
Copy link

@WardF , I tried building UDUNITS2 with CMAKE following your directions:

$ cd c:\programs\udunits-2-master
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_PREFIX_PATH=c:\programs\expat32_2.1.0  -G"Visual Studio 9 2008"
$ cmake --build . --config Release --target libudunits2
$ cmake --build . --config Release --target udunits2

but got back:

c:\RPS\UDUNITS-2-master\build>cmake .. -DCMAKE_PREFIX_PATH=c:\programs\expat32_2
.1.0 -G"Visual Studio 9 2008"
-- Building Windows DLL: ON
DEFAULT_UDUNITS2_XML_PATH = "C:\\Program Files (x86)\\udunits\\share\\udunits\\u
dunits2.xml"
-- Could NOT find EXPAT (missing:  EXPAT_LIBRARY EXPAT_INCLUDE_DIR)
CMake Error at CMakeLists.txt:161 (MESSAGE):
  Unable to find an EXPAT library.
@rsignell-usgs
Copy link
Author

Okay, I was able to fix this by setting EXPAT_INCLUDE_DIR:

c:\RPS\UDUNITS-2-master\build>cmake .. -DCMAKE_PREFIX_PATH=c:\programs\expat32_2
.1.0 -DEXPAT_INCLUDE_DIR=c:\programs\expat32_2.1.0\source\lib -G"Visual Studio 9
 2008"
-- Building Windows DLL: ON
DEFAULT_UDUNITS2_XML_PATH = "C:\\Program Files (x86)\\udunits\\share\\udunits\\udunits2.xml"
-- Found EXPAT: c:/programs/Expat32_2.1.0/Bin/libexpat.lib (found version "2.1.0")
-- Unable to find CUnit library. Unit-testing not enabled.
-- Configuring done
-- Generating done
-- Build files have been written to: C:/RPS/UDUNITS-2-master/build

@WardF
Copy link
Member

WardF commented Aug 19, 2014

@rsignell-usgs I'm glad you got it going. It took some doing to make NetCDF-cmake work transparently in this sort of situation. I'm sure I'll find some time to make the udunits2-cmake a little more robust :).

Glad to see this is proving useful!

@rsignell-usgs
Copy link
Author

Look just how useful! Gohlke built Iris for windows last night, using your udunits2-2.2.16!!!!
https://www.lfd.uci.edu/~gohlke/pythonlibs/#iris
Proof that it works!
SciTools/iris#467

@semmerson
Copy link
Collaborator

@rsignell-usgs Yea. I'm glad this appears to be somewhat useful.

@pelson
Copy link

pelson commented Nov 14, 2014

For the record, I had to define -DEXPAT_LIBRARY=<path to lib dir containing libexpat.lib> to fix this problem.

@IrfanTak
Copy link

Hello, I need a Windows binary for the UDUNITS or UDUNITS2 asap. As you can see from the following link, I am still stuck: https://stackoverflow.com/questions/29657170/migration-of-perl-code-to-windows-missing-udunits-package Thanks in advance.

@pelson
Copy link

pelson commented Apr 15, 2015

You can download a pre-built one with miniconda if you have it installed. conda install -c scitools udunits should do the trick... to see how that is built, take a look at https://github.com/SciTools/conda-recipes-scitools/blob/master/udunits/bld.bat.

@IrfanTak
Copy link

Hi @pelson
I will check our the conda; I wish I can just find a binary! I have already installed so many other things.
I am also trying this: #18
Thanks.

@IrfanTak
Copy link

No, I don't have conda recipe and nor do I want to install anything anymore. Can someone please put the ununits or udunits2 binary somewhere for me to grab? I have exhausted hours on this already and the real work is yet to even begin. Thanks!

@WardF
Copy link
Member

WardF commented Apr 15, 2015

Hi @meengla,

"For Windows" is a bit nebulous. I'm unfamiliar with ActivePerl, but in general programs for 'Windows' are typically linked against one of three C runtime libraries; either the gcc libc runtime (cygwin), the mingw runtime (mingw port/fork of gcc) or the Visual Studio C++ runtime. There are also others, but these are the three that seem to be most commonly used.

Which would be appropriate for ActivePerl? I cannot provide a pre-built binary; I'm out of the office and away from my Windows development machine until next week. I can try to provide guidance re: using cmake to build it, however.

The complicating factor will be libexpat; you will need to find/build a copy of libexpat built with the same compiler as appropriate for ActivePerl. I recall having to do this to get UDUNITS2 compiling with MSVC, but I would have to go back and dig through my notes.

@IrfanTak
Copy link

Hi @WardF ,
I could wait for a few more days if you or someone could provide a binary. But I don't know what binary would be useful. My scenario is per: https://stackoverflow.com/questions/29657170/migration-of-perl-code-to-windows-missing-udunits-package
Thanks!

@pelson
Copy link

pelson commented Apr 15, 2015

@WardF - for the record, we are building expat in the same repo as previous link (https://github.com/SciTools/conda-recipes-scitools/blob/master/expat/bld.bat)

@WardF
Copy link
Member

WardF commented Apr 15, 2015

Hello @mengla; following the link you provide from stackoverflow I cannot find for sure what environment is needed, but it appears that perhaps it is mingw? Have you tried contacting the "Fossies" project for support?

Without knowing anything about ActivePerl and not knowing what the state of libexpat under mingw is, it's unclear if I could build anything that would be of use to you and, if so, when I'd have a chance to sit down and figure it out. So, you may want to proceed trying to compile udunits2 manually; what errors are you receiving from cmake? My guess would be that they are related to libexpat, unless you already have a mingw compatible copy?

@WardF
Copy link
Member

WardF commented Apr 15, 2015

Update; I see now that I misread the following:


3.2.4 Windows Installation Instructions

Currently, only a 32-bit MinGW-based installation is supported:

 cmake -G "MinGW Makefiles"
 cmake --build . [-DCMAKE_INSTALL_PREFIX=dir] -- all [test] install [install_test] where arguments in square brackets are optional.

The default installation-prefix is "C:\Program Files (x86)\udunits-2.minor.bug", where minor and     bug are the minor version and bug-fix level, respectively.

This information is out of date, as I know for sure that 32 and 64-bit Visual Studio builds are also supported. This does set us back, however, as my guess that MinGW is the appropriate environment is now unsubstantiated. Before proceeding we would need to know what the appropriate environment was.

@IrfanTak
Copy link

Hi @WardF ,
My ActivePERL environment is able to load other .pm or modules just fine in the legacy .pl and legacy .pm files. So I am reasonably confident, after fixing Linux vs Windows paths and making Wdunits to work, I should be good.
I see your post from just now, just above: Yes, I tried MinGW using CMake Gui to compile and managed to get it sort of compile but never any .DLL produced.
I don't know what to do now--I was looking into a solution above where someone (@rsignell) was able to make manual/command line compile to work and I am thinking of testing that.
Thanks!

@IrfanTak
Copy link

Okay, I use command line way now: cmake CC="C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\cl.exe" CXX="C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\cl.exe" -DEXPAT_LIBRARY=c:\expat32\Bin\libexpat.dll ..
and I can see that 'configuring done' and 'generating done' but also a message like CUNIT not found. Build files are written to a folder; but where is the DLL? I am quite new to this so sorry if too simple questions.

@WardF
Copy link
Member

WardF commented Apr 16, 2015

Not a problem; using the Microsoft compiler actually makes this easier for me, since I am more familiar with cmake+MSVC on Windows than I am mingw.

You will want to make the following changes:

  • instead of CC and CXX and the corresponding assignments, use -G"Visual Studio 11" or -G"Visual Studio 11 Win64" for 32 or 64 bit builds, respectively.
  • instead of pointing EXPAT_LIBRARY to a DLL file, there should be a corresponding 'import library', with the same name except with a .lib suffix instead of .dll.

Finally, once cmake finishes configuring, you will build from the command line using:

$ cmake build . 

You may need to specify that you want a 'release' build. Muscle memory is failing me but you would do the following I believe:

$ cmake --build . --config=Release 

After this you should be able to search for udunits2.dll and udunits2.lib. Note that the later is the import library you would link against, not the dll directly in any project which links against us units when compiling.

Please note I'm currently on my phone so I can't double check file names or option names, but everything should be correct or nearly so.

@IrfanTak
Copy link

Okay, I will try your latest too. Right now, I am trying to implement your solution from August 6, 2014.
Thanks.

#16

@IrfanTak
Copy link

Here is my latest command--it still can't find the Expat library: cmake DEXPAT_INCLUDE_DIR=c:\expat32\source\lib -DEXPAT_LIBRARY=c:\expat32\Bin\libexpat.lib CC="C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\cl.exe" CXX="C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\cl.exe" --build . --config Release --target libudunits2 --build . --config Release --target udunits2 ..
Note, the command is run inside a folder: C:\Users\xxxx\Desktop\db_Xenia\UDUNITS-2-master\build

@IrfanTak
Copy link

And here is even latest command--note, I have now referencing osGeo' as well as expat32 folders; no compile error but still no DLL; I must be close?!
cmake CC="C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\cl.exe" CXX="C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\cl.exe" -DEXPAT_INCLUDE_DIR=C:\OSGeo4W64\lib -DEXPAT_LIBRARY=c:\expat32\Bin\libexpat.dll --build . --config Release --target libudunits2 --build . --config Release --target udunits2 .. screen cap of the output to follow

@IrfanTak
Copy link

Here is the screen cap of the last output: https://img42.com/NcjPV

@IrfanTak
Copy link

Probably even closer; after the above commands, I also ran: cmake --build . --config Release and now I see one fatal error: expat.h not found in a vsxproj ; so I must have not included the Expath Library correctly?

@IrfanTak
Copy link

Aha ha! Even closer: cmake .. -DCMAKE_PREFIX_PATH=c:\expat32 -G "Visual Studio 11" -DEXPAT_INCLUDE_DIR=C:\expat32\Source\lib -DEXPAT_LIBRARY=c:\expat32\Bin\libexpat.lib

and then:
cmake --build . --config Release

Plenty of Warnings but no error...

@WardF
Copy link
Member

WardF commented Apr 16, 2015

Hello, sorry for the delayed response I've just seen all of your messages at once. Still on my phone :).

Warnings are acceptable! As I recall there were plenty of them for me as well. Unfortunately, the test programs depend on ctest, which is not available on windows. This was an issue with the initial porting as well, and my announcement more or less was that I will assume it works until I am told that it does not.

Congratulations on your perseverance! Hopefully this should be what you need to proceed with your initial project!

@WardF
Copy link
Member

WardF commented Apr 16, 2015

Update: upon reflection is is not ctest upon which the tests depend, but some other framework which is unavailable on windows but whose name escapes me.

@semmerson
Copy link
Collaborator

CUnit

Regards,
Steve Emmerson

On Thu, Apr 16, 2015 at 12:52 PM, Ward Fisher [email protected]
wrote:

Update: upon reflection is is not ctest upon which the tests depend, but
some other framework which is unavailable on windows but whose name escapes
me.


Reply to this email directly or view it on GitHub
#18 (comment).

@IrfanTak
Copy link

Thank you all again, especially @WardF ; my Release folder has 3 files: udunits2.dll, udunits2.lib, and udunits2.exp ; I presume I could simply copy them into C:\Perl64\lib\auto folder and call like simply call, something like: https://community.activestate.com/node/10060 ? I know, it is probably not in the scope of this page but thought to do a quick check. The legacy code is calling like: use UDUNITS; and then initializing: UDUNITS::init('/usr/local/udunits/etc/udunits.dat');
Thanks!

@IrfanTak
Copy link

Well, I don't know how to use the fruit of my hard work (the .DLL) in a Perl script! I posted at Stackoverflow but not getting anywhere so far: https://stackoverflow.com/questions/29685765/using-a-custom-made-dll-inside-active-perl-scripts
I am now trying to deploy the PERL scripts in another Linux environment now...

@IrfanTak
Copy link

Never mind--my own ignorance! Compiling to a DLL was probably not the way; I need to look into making a PERL module from the UDUNITS2...

@lucianainpa
Copy link

Hello, I have a problem in the instalation ncview-1.2.7
I have this message:

Could not find the expat library despite the fact that the udunits2 library is installed. This probably means some sort of configuration file error. Please consult with the package maintainer.
Does anyone know how I can solve it?

@semmerson
Copy link
Collaborator

@lucianainpa Is the Expat development package installed? If not, can you install it?

@lucianainpa
Copy link

Hi @semmerson
I installed Expat and solved the problem.
Thank you!

1 similar comment
@lucianainpa
Copy link

Hi @semmerson
I installed Expat and solved the problem.
Thank you!

@lucianainpa
Copy link

Hello everyone,
I was trying to install netcdf 4.1.3 and in the end gave this error. Can anybody help me?

Makefile:1070: recipe for target 'check-TESTS' failed
make[2]: *** [check-TESTS] Error 1
make[2]: Leaving directory '/usr/local/netcdf-4.1.3/nc_test4'
Makefile:1192: recipe for target 'check-am' failed
make[1]: *** [check-am] Error 2
make[1]: Leaving directory '/usr/local/netcdf-4.1.3/nc_test4'
Makefile:551: recipe for target 'check-recursive' failed
make: *** [check-recursive] Error 1

@semmerson
Copy link
Collaborator

@lucianainpa You should do what the error message said and send the output to [email protected].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants