Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: preprocessor idea Date: Tue, 11 Oct 2011 21:57:12 +0200 Lines: 48 Message-ID: <9fjlcpFdmU1@mid.individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net w1yKn+uRkeOjOzhXEZvnLgEmloSNYRxSPKAkYT7oJyP71tLXQ= Cancel-Lock: sha1:ff88GutsQFjTI1TuwMkQnZLucoA= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110922 Lightning/1.0b2 Thunderbird/3.1.15 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8714 On 10/11/2011 08:19 PM, Philipp Kraus wrote: > I use within my Java code different external libraries (DLL), so I have > create a string array with their names > so the libraries can be load with System.load / System.loadLibrary. That's the wrong approach IMHO: make the interface classes load the DDL they need at class load time (e.g. in a static initializer block). This best fits the Java model of dynamically deciding what code to use. > I build the libraries (C++ code) with a toolchain and I use a lot of > preprocessor commands within > the C++ code, so I can enable or disable some function and so the using > of the libraries eg: > > Thanks > > Phil > Why do you want to decide this in C++ land? > c++: > #ifdef lib1 > #endif > > #ifdef lib2 > #endif > > So my Java code must load lib1 and lib2 if both defs are set. Java does > not support any preprocessor > flags, but in this case I need a tip for creating a flexiable Java code > during the class is compiled > (eg: ifdef1 = true => String[] javaarray = {"lib1"}). Do you know any > idea for this problem? Again, IMHO this is the wrong approach: you should create your libraries with all the functionality you need and only determine via Java classes which are used or not used what DLLs are loaded and used. If you really want to make the decision in C++ land you could use your preprocessor to have different variants of a JNI method which returns information which lets you determine in Java which DLL's to load. You could have a native method which returns a String[] with DLL names etc. Kind regards robert