On Thu, Jul 29, 2010 at 10:35 PM,
<[email protected]>wrote:

> Send NLopt-discuss mailing list submissions to
>        [email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss
> or, via email, send a message with subject or body 'help' to
>        [email protected]
>
> You can reach the person managing the list at
>        [email protected]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of NLopt-discuss digest..."
>
>
> Today's Topics:
>
>   1. Re: Visual Studio and NLOpt (Benoit Scherrer)
>   2. Re: Visual Studio and NLOpt (Steven G. Johnson)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 29 Jul 2010 22:24:41 -0400
> From: Benoit Scherrer <[email protected]>
> Subject: Re: [NLopt-discuss] Visual Studio and NLOpt
> To: "Steven G. Johnson" <[email protected]>
> Cc: [email protected]
> Message-ID:
>        
> <[email protected]<aanlktinlg_dbxpt%[email protected]>
> >
> Content-Type: text/plain; charset="iso-8859-1"
>
> On Thu, Jul 29, 2010 at 9:52 PM, Benoit Scherrer
> <[email protected]>wrote:
>
> >
> >
> > On Thu, Jul 29, 2010 at 9:14 PM, Steven G. Johnson <
> [email protected]>wrote:
> >
> >> Thanks for looking into this, Benoit!  Does this build a static library
> >> (.lib) or a shared library (.dll), or both?
> >>
> >>
> > Thanks! that's true currently it is only for a static library. It could
> be
> > good to also have the option to compile
> > as a shared library with CMake, i will do that.
> >
> >
> >
> >
> >> On Jul 29, 2010, at 8:27 PM, Be-noix wrote:
> >>
> >>> - rename #include "config.h" to #include "config_nlopt.h"
> >>> because my project already had a config.h (bad idea)
> >>>
> >>
> >> This doesn't make sense to me.  Surely you are compiling NLopt as a
> >> library?  In which case the config.h file is internal to NLopt and is
> >> irrelevant to programs using NLopt.  Programs using NLopt need only
> include
> >> the nlopt.h header and link the NLopt library.
> >>
> >
> >
> > That's true that for the nlopt library itself there is no problem.
> > But in my project i was including both api/nlopt.h and util/nlopt-util.h
> > (to use the function nlopt_seconds)
> > This nlopt-util.h file includes config.h, and there were some conflicts.
> >
> >
> >
> >>  because VC was in 'C' mode, and not 'C++', and you can define a
> >>> variable only at the beginning of a block in C
> >>>
> >>
> >> Actually, mixed declarations and code have been been a standard part of
> C
> >> for 11 years now.  But I generally try to stick with 1989 C anyway, and
> I
> >> will fix the two instances you spotted in the next NLopt release.
> >>
> >> (With these two fixes, it now compiles with gcc -std=c89 -pedantic.)
> >>
> >>  (I tried for one hour to force VC to use C++ but without any success)
> >>>
> >>
> >> If NLopt is not compiling as C++, I'd be interested to hear what the
> >> problems are.  I can compile with "g++ -pedantic -ansi" without
> problems.
> >>
> >
> >
> > No no it's definitely compiling as C++, what i said was not clear. The
> > thing is that in VS (if i don't make a mistake)
> > all files with .c are compiled as C, and cxx/cpp as C++. By renaming
> > optimize.c to optimize.cxx there is no more
> > 'block' error. Another option: in the VS interface i could select the
> file
> > optimize.c and manually set the flag /TP to force its
> > compilation in C++ and there wouldn't be the 'block' error. I tried to
> set
> > that flag /TP in the CMakeLists.txt
> > but it didn't worked.
> >
> > That's strange because VS is generally really less stringent than gcc
> about
> > the norms, and so here it seems it sticks
> > as you said to the 1989 C and not gcc.
> >
> >
> >>
> >>  And success!
> >>> Maybe Steven you could include these modifs in the original source
> code?
> >>> (and if you want to CMakeList.txt ?)
> >>>
> >>
> >> I'd be happy to post the CMakeList.txt on the web site, although I'd
> >> prefer not to change the name of the config.h header file as explained
> >> above.
> >>
> >
> >  sure. But what do you think about my problem with nlopt-util? Is the
> > include of config.h really necessary in that
> > file?
> >
> >
> >>  Steven
> >>
> >> PS. I notice that the C99/IEEE function copysign is missing on Windows
> so
> >> you defined a macro, although apparently Microsoft defined a _copysign
> >> function because they love to be different.  I'll include a check for
> this
> >> in the next release.
> >>
> >
> > yes that's true. In fact i did have a linker warning about _copysign (but
> > not a compiler warning, so VS knew
> > what was that function). And i didn't tried to look in which lib
> > in _copysign , i just made the macro.
> >
> > Benoit
> >
> > --
> > / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
> /
> > / /
> > Benoit Scherrer
> > Postdoctoral Research Fellow
> > Computational Radiology Laboratory,
> > Harvard Medical School (Boston)
> >
> > http://www.crl.med.harvard.edu/
> > http://www.BenoitScherrer.com
> > / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
> /
> > / /
> >
>
>
> Here is a CMakeLists.txt with an option to choose between static or shared
>
> Also, i didn't found any dllexport in the original source code.
>
> So for win32, in nlopt.h, i modified it to be:
>
> #if defined(NLOPT_DLL) && (defined(_WIN32) || defined(__WIN32__))
> /* annoying Windows syntax for calling functions in a DLL */
>
>    #ifdef NLOPT_EXPORT
>  #define NLOPT_EXTERN(T) __declspec(dllexport) T NLOPT_STDCALL
> #else
> #define NLOPT_EXTERN(T) extern __declspec(dllimport) T NLOPT_STDCALL
>  #endif
>
> #else
> (...)
>
> With such a code and with the CMakeLists.txt, when the option 'Compile as
> shared' is selected,
> then both NLOPT_DLL and NLOPT_EXPORT  are defined and __declspec(dllexport)
> is used
>
> If the user want to import the nlopt.dll, he sets only NLOPT_DLL in his
> project  and __declspec(dllimport)
> is used.
>
> I checked it seems to compile (it does create a dll).
> didn't tried the shared option on linux yet....
>
> Benoit
>
> Benoit
>
>
>
> #==============================================================================
> # NLOPT CMake file
> #
> # NLopt is a free/open-source library for nonlinear optimization, providing
> # a common interface for a number of different free optimization routines
> # available online as well as original implementations of various other
> # algorithms
> # WEBSITE: http://ab-initio.mit.edu/wiki/index.php/NLopt
> # AUTHOR: Steven G. Johnson
> #
> # This CMakeLists.txt file was created to compile NLOPT with the CMAKE
> utility.
> # Benoit Scherrer, 2010 CRL, Harvard Medical School
> # Copyright (c) 2008-2009 Children's Hospital Boston
> # Minor changes to the source was applied to make possible the compilation
> with
> # Cmake under Linux/Win32
>
> #==============================================================================
>
>
> CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
> INCLUDE(CheckIncludeFiles)
> INCLUDE(CheckFunctionExists)
> INCLUDE(CheckTypeSize)
>
>
>
> #==============================================================================
> # COMPILATION CHECKINGS and CONFIGURATION GENERATION
>
> #==============================================================================
> CHECK_INCLUDE_FILES( unistd.h HAVE_UNISTD_H)
> CHECK_INCLUDE_FILES( string.h HAVE_STRING_H)
> CHECK_INCLUDE_FILES( strings.h HAVE_STRINGS_H)
> CHECK_INCLUDE_FILES( sys/stat.h HAVE_SYS_STAT_H)
> CHECK_INCLUDE_FILES( inttypes.h HAVE_INTTYPES_H)
> CHECK_INCLUDE_FILES( memory.h HAVE_MEMORY_H)
> CHECK_INCLUDE_FILES( stdlib.h HAVE_STDLIB_H)
> CHECK_INCLUDE_FILES( stdint.h HAVE_STDINT_H)
>
> CHECK_INCLUDE_FILES( sys/types.h HAVE_SYS_TYPES_H)
> CHECK_INCLUDE_FILES( sys/types.h HAVE_SYS_TYPES_H)
> CHECK_INCLUDE_FILES( sys/types.h HAVE_SYS_TYPES_H)
>
> CHECK_FUNCTION_EXISTS( isinf HAVE_ISINF)
> CHECK_FUNCTION_EXISTS( isinf HAVE_ISNAN)
> CHECK_FUNCTION_EXISTS( gettimeofday HAVE_GETTIMEOFDAY)
> CHECK_FUNCTION_EXISTS( qsort_r HAVE_QSORT_R)
> CHECK_FUNCTION_EXISTS( time HAVE_TIME)
>
> CHECK_TYPE_SIZE(uint32_t    UINT32_T)
> IF(NOT HAVE_UINT32_T)
>  IF(MSVC)
>    SET(uint32_t "unsigned int")
>    SET(SIZEOF_UNSIGNED_INT 4)
>  ENDIF(MSVC)
> ENDIF(NOT HAVE_UINT32_T)
>
> SET( NLOPT_MAJOR_VERSION 2 )
> SET( NLOPT_MINOR_VERSION 2 )
>
> CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.h.in
> ${PROJECT_BINARY_DIR}/config_nlopt.h
> IMMEDIATE )
>
>
>
> #==============================================================================
> # INCLUDE DIRECTORIES
>
> #==============================================================================
> INCLUDE_DIRECTORIES (
> ${CMAKE_CURRENT_SOURCE_DIR}
>        ${PROJECT_BINARY_DIR}
> stogo
> util
> direct
>  cdirect
> praxis
> luksan
>  crs
> mlsl
> mma
>  cobyla
> newuoa
> neldermead
>  auglag
> bobyqa
> isres
>  slsqp
> api   )
>
>
>
> #==============================================================================
> # nlopt LIBRARY TARGET (SHARED OR STATIC)
>
> #==============================================================================
>
> SET ( NLOPT_SOURCES
> direct/DIRect.c direct/direct_wrap.c direct/DIRserial.c direct/DIRsubrout.c
> direct/direct-internal.h direct/direct.h
>  cdirect/cdirect.c cdirect/hybrid.c cdirect/cdirect.h
> praxis/praxis.c praxis/praxis.h
>  luksan/plis.c luksan/plip.c luksan/pnet.c luksan/mssubs.c luksan/pssubs.c
> luksan/luksan.h
> crs/crs.c crs/crs.h
>  mlsl/mlsl.c mlsl/mlsl.h
> mma/mma.c mma/mma.h
> cobyla/cobyla.c cobyla/cobyla.h
>  newuoa/newuoa.c newuoa/newuoa.h
> neldermead/nldrmd.c neldermead/neldermead.h neldermead/sbplx.c
>  auglag/auglag.c auglag/auglag.h
> bobyqa/bobyqa.c bobyqa/bobyqa.h
> isres/isres.c isres/isres.h
>  slsqp/slsqp.c slsqp/slsqp.h
> api/general.c api/options.c api/optimize.c api/deprecated.c
> api/nlopt-internal.h api/nlopt.h api/f77api.c api/f77funcs.h
> api/f77funcs_.h
> api/nlopt.hpp api/nlopt-in.hpp
>  util/mt19937ar.c util/sobolseq.c util/soboldata.h util/timer.c util/stop.c
> util/nlopt-util.h util/redblack.c util/redblack.h util/qsort_r.c
> util/rescale.c
>  stogo/global.cc stogo/linalg.cc stogo/local.cc stogo/stogo.cc
> stogo/tools.cc stogo/global.h stogo/linalg.h stogo/local.h
> stogo/stogo_config.h stogo/stogo.h stogo/tools.h
>        )
>
> OPTION(NLOPT_BUILD_SHARED "Build NLOPT as a shared library" OFF )
>
> IF(NLOPT_BUILD_SHARED)
>  ADD_DEFINITIONS(-DNLOPT_DLL -DNLOPT_EXPORT)
>  ADD_LIBRARY (nlopt SHARED ${NLOPT_SOURCES} )
> ELSE(NLOPT_BUILD_SHARED)
>  ADD_LIBRARY (nlopt STATIC ${NLOPT_SOURCES} )
> ENDIF(NLOPT_BUILD_SHARED)
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://ab-initio.mit.edu/pipermail/nlopt-discuss/attachments/20100729/22d82adc/attachment-0001.htm
> >
>
> ------------------------------
>
> Message: 2
> Date: Thu, 29 Jul 2010 22:35:33 -0400
> From: "Steven G. Johnson" <[email protected]>
> Subject: Re: [NLopt-discuss] Visual Studio and NLOpt
> To: [email protected]
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
>
>
> On Jul 29, 2010, at 9:52 PM, Benoit Scherrer wrote:
> > That's true that for the nlopt library itself there is no problem.
> > But in my project i was including both api/nlopt.h and util/nlopt-
> > util.h (to use the function nlopt_seconds)
> > This nlopt-util.h file includes config.h, and there were some
> > conflicts.
>
> In general, one should be cautious about using undocumented internal
> functions.  However, if you want to do so, I would suggest copying
> only the declaration of the function you want (rather than including
> the whole nlopt-util.h and config.h headers).  That is, paste:
>
>        extern double nlopt_seconds(void);
>
> into your code.
>
>

Yes you're right, i didn't realize that nlopt_seconds was an internal
function,
but it is.

Thanks
Benoit
_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss

Reply via email to