The SimbaEngine SDK enables you to build and develop custom ODBC Drivers for Windows, Linux, and many other platforms to connect your data source to any application through an ODBC interface. On Windows, you build drivers via a Visual Studio project, and on Linux you use makefiles to build your driver. On the Linux platform you must modify these makefiles based on the additional work you have done. In this post, I will go over what and where you need to make changes in the makefiles to build your ODBC driver and what you need to do to run your ODBC driver on Linux.
Building the ODBC driver:
- Open your terminal, navigate to your driver project, and go to the “Makefiles” directory.
- Rename the makefile to be the name of your project.
- Go into the “Makedepend” directory and change the name of the .depend file to be the same as your project name you named your .mak file.
- Return to your project’s root directory (cd ../../) and go into “Source”. There are two makefiles that you will need to edit: Makefile_FLAGS.mak and Makefile_SRCS.mak.
- Open Makefile_FLAGS.mak in a text editor. This file contains all the directories to include and any libraries to include for your driver. Under the COMMON_CFLAGS section you can add any directories that need to be included in your driver project. For example, if a new folder called Passdown was created in your DataEngine folder for passdown classes you would add in –I ./DataEngine/Passdown to the list. Note that “\” is used to separate each include. You will also have to add any directories containing headers for third-party libraries that your driver depends on. If you have third-party libraries that need to be linked then you can edit COMMON_LDFLAGS to link to your third-party libraries. There are multiple COMMON_LDFLAGS in the makefile which corresponds to the platform you are building on, so ensure you edit the COMMON_LDFLAGS of the platform you are building on. Remember to order your libraries according to the dependencies it may have. For example, if Library A depends on Library B, then put Library A before Library B. You can also change the build configuration according to environment variables, for example you can use the ARCH and BITNESS environment variables to define the architecture and bitness of libraries to use, respectively. Once you are done adding in your includes save the file.
- Open Makefile_SRC.mak for editing using a text editor. Makefile_SRC.mak contains the location of each source file in your driver. Add any other source files your driver requires by adding it to the COMMON_SRCS Make sure to include the extensions of the new source files to avoid build problems. In addition, the makefile also contains the source file for your driver entry-point, named Main_Unix.cpp in all of the samples provided with the SDK. You may define different source files to use depending on the platform you are using by checking the OS environment variable (AIX, HP-UX, Solaris, Darwin).
- Once you modify the .mak files, navigate back to the Makefiles directory (cd ../Makefiles). Make sure to define the environment variables in the command line for where you have installed the SimbaEngine SDK. To build a Linux driver you need to have SIMBAENGINE_DIR and SIMBAENGINE_THIRDPARTY_DIR environment variables defined. The SIMBAENGINE_DIR represents the location of your DataAccessComponents folder of your SimbaEngineSDK installation and the SIMBAENGINE_THIRDPARTRY_DIR will point to the ThirdParty directory of your installation. Using these environment variables, your makefiles can access our predefined makefiles to take care of building the SimbaEngine components of your driver. You can define those environment variables by the following commands in the command line. Replace <DIR_OF_SIMBAENGINE> with the actual directory of the SimbaEngineSDK on your computer.
12export SIMBAENGINE_DIR = <DIR_OF_SIMBAENGINE>/ SimbaEngineSDK/9.5/DataAccessComponentsexport SIMBAENGINE_THIRDPARTY_DIR = <DIR_OF_SIMBAENGINE>/ SimbaEngineSDK/9.5/DataAccessComponents/ThirdParty
Note that the version of the SDK may be different depending on what you have installed.
- Build the driver on Linux by typing
make –f .mak [release/debug] [ARCH=x86/ARCH=x8664]
Example: make –f Quickstart.mak release ARCH=x8664
To build the ODBC driver in a server configuration you would add in the argument BUILDSERVER=exe to your make command. For more information about building a driver in the server configuration please refer to our blog post on Building an ODBC Driver as a Server. Once the build is complete then you can navigate to the Bin directory, there should be a directory named either Linux_x86 or Linux_x8664 which will have your driver built in the bitness defined in ARCH. Note for building a driver on AIX or Solaris platforms you must use another argument called USE_GCC and set it to 1 to force the use of the GCC compiler. For more information regarding building a driver on Linux environment please refer to our SimbaEngine Developer Guide. Now you have successfully built a driver on a Linux platform.
Setting up Data Source on Linux
After you have built your driver you will have to set it up as a DSN (Data Source Name) and Driver to use it. The Driver Manager will read odbc.ini and odbcinst.ini to get the DSN and Driver respectively. These files should be hidden files in your home directory, but if they do not exist then you can take the sample files which are located in the Setup folder in the Documentation directory of the SimbaEngine SDK.
- Open odbcinst.ini using a text editor and add in the name of your driver to the ODBC Drivers Section with a value of Installed.
- Create a new section in the file with the same name as your driver you defined in the previous step.
- Add a key called Driver to your newly defined section and set it to the location of your driver on the machine.
- Save and close odbcinst.ini.
You should have added to following to odbcinst.ini
12345[ODBC Drivers]MyODBCDriver = Installed[MyODBCDriver]Driver=/localhome/username/Documents/MyODBCDriver/Bin/Linux_x8664/libMyODBCDriver.so
- Open odbc.ini using a text editor and add the name of your DSN under the ODBC Data Sources section and set the value to the driver you defined in odbcinst.ini.
- Create a new section with the same name as your DSN that was defined under the ODBC Data Sources section.
- Enter your path to your driver under a Driver key.
- You may also enter any additional connection settings in this section such as user credentials, etc.
- Save and close odbc.ini
You should have added something like the following to odbc.ini
1234567[ODBC Data Sources]MyDataSource = MyODBCDriver[MyDataSource]Driver=/localhome/username/Documents/MyODBCDriver/Bin/Linux_x8664/libMyODBCDriver.soUID = UserPWD = Password
Running the ODBC Driver
When you want to run the driver, you must specify the binaries the driver uses by defining them in LD_LIBRARY_PATH environment variable. For example, every driver developed using the SimbaEngine SDK will use ICU binaries so in LD_LIBRARY_PATH we define the path to where the ICU binaries are.
For a 32 bit driver that does not use any additional third-party libraries you can use the following command.
For a 64 bit driver.
If your driver had additional third-party libraries then you would append on the paths to the LD_LIBRARY_PATH environment variable using “:” to separate each path.
For example if we had a 64 bit driver using a 64 bit third party library located at /localhome/user/Documents/ThirdParty then our export would be:
Once you have modified the LD_LIBARARY_PATH environment variable your ODBC driver is ready for use. You can use a test application like iodbctest to issue a query to your data source using your driver. To use iodbctest you must have the iODBC Driver Manager installed on your machine. Start iodbctest by typing iodbctest in your terminal and provide the name of your DSN defined in odbc.ini to the test application in the connection string, then you will be able to issue a SQL query to your data source using your SimbaEngine built ODBC driver.