2009/04/01
MySQL 매뉴얼에 포함되어 있는 Connector/C++ 이용한 프로그램 작성
필요할 때가 있을 것 같아서 접근하기 쉽도록 MySQL 매뉴얼에 포함되어 있는 Connector/C++ 컴파일 방법을 스크랩 하였다.
20.6.3. MySQL Connector/C++ Building applications on Windows
MySQL Connector/C++ is available as a static or dynamic library to use with your application. This section looks at how to link the library to your application.
Static library
The MySQL Connector/C++ static library file is mysqlcppconn-static.lib. This needs to be statically linked with your application. You also need to link against the files libmysql.dll and libmysql.lib. Once linking has been successfully completed, the application will require access to libmysql.dll at run time.
Dynamic library
The MySQL Connector/C++ dynamic library file is mysqlcppconn.dll. In order to build your client application you need to link it with the file mysqlcppconn.lib. At run time the application will require access to the files mysqlcppconn.dll and libmysql.dll.
Building an application using the static library - step-by-step
Building an application to use the dynamic library - step-by-step
20.6.3. MySQL Connector/C++ Building applications on Windows
MySQL Connector/C++ is available as a static or dynamic library to use with your application. This section looks at how to link the library to your application.
Static library
The MySQL Connector/C++ static library file is mysqlcppconn-static.lib. This needs to be statically linked with your application. You also need to link against the files libmysql.dll and libmysql.lib. Once linking has been successfully completed, the application will require access to libmysql.dll at run time.
Dynamic library
The MySQL Connector/C++ dynamic library file is mysqlcppconn.dll. In order to build your client application you need to link it with the file mysqlcppconn.lib. At run time the application will require access to the files mysqlcppconn.dll and libmysql.dll.
Building an application using the static library - step-by-step
- Select File, New, Project from the main menu. Then in the wizard select Visual C++, Win32. From Visual Studio Installed Templates select the application type Win32 Console Application. Enter a name for the application, and then click OK, to move to the Win32 Application Wizard.
- In the Win32 Application Wizard, click on Application Settings and ensure the defaults are selected. The radio button Console application, and the checkbox Precompiled headers will be selected.
- From the drop down list box on the toolbar, change from the default Debug build to the Release build.
- From the main menu select Project, Properties. This can also be accessed using the hot key ALT + F7.
- Under Configuration Properties, open the tree view.
- Select C++, General in the tree view. Then in the Additional Include Directories text field, add include/.
- In the same tree view under Linker, General, add lib/opt into the Additional Library Directories text field.
- Also in Linker, General, Additional Library Directories, add MySQL Server lib/opt for libmysql.lib.
- Then in Linker, Input, Additional Dependencies, enter mysqlcppconn-static.lib and libmysql.lib.
------ Rebuild All started: Project: cpp_static_client, Configuration: Release Win32 ------
Deleting intermediate and output files for project 'cpp_static_client', configuration 'Release|Win32'
Compiling...
cpp_static_client.cpp
stdafx.cpp
Linking...
cpp_static_client.obj : error LNK2001: unresolved external symbol __imp__get_driver_instance
cpp_static_client.obj : error LNK2001: unresolved external symbol "__declspec(dllimport)
public: int __thiscall sql::SQLException::getErrorCode(void)const "
(__imp_?getErrorCode@SQLException@sql@@QBEHXZ)
cpp_static_client.obj : error LNK2001: unresolved external symbol "__declspec(dllimport)
public: class std::basic_string,
class std::allocator> const & __thiscall
sql::SQLException::getSQLState(void)const "
(__imp_?getSQLState@SQLException@sql@@QBEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
C:\Dokumente und Einstellungen\T60\Eigene Dateien\Visual Studio 2008\Projects
\cpp_static_client\Release\cpp_static_client.exe : fatal error LNK1120: 3 unresolved externals
Build log was saved at "file://c:\Dokumente und Einstellungen\T60\Eigene Dateien\Visual Studio 2008\
Projects\cpp_static_client\cpp_static_client\Release \BuildLog.htm"
cpp_static_client - 4 error(s), 0 warning(s) - In the Project, Properties tree view, under C++, Preprocessor, enter CPPCONN_PUBLIC_FUNC= into the Preprocessor Definitions text field.
Building an application to use the dynamic library - step-by-step
- From the main menu select File, New Project. Then in the wizard select Visual C++, Win32. Under Visual Studio installed templates select Win32 Console Application. Enter a suitable name, and then click OK to enter the Win32 Application wizard.
- In the Win32 Application Wizard, click on Application Settings. Use the default settings. The Console application radio button, and Precompiled header checkbox should be selected. Click Finish to close the wizard.
- From the drop down list box on the toolbar, change from the default Debug build to the Release build.
- From the main menu select Project, Properties. This can also be accessed using the hot key ALT + F7.
- Under Configuration Properties, open the tree view.
- Under C++, General, add include/ into the Additional Include Directories text field.
- Under Linker, General, add lib/opt into the Additional Library Directories text field.
- Under Linker, Input, add mysqlcppconn.lib into the Additional Dependencies text field.
- In the Editor, copy standalone_example_docs1.cpp, and add #include "stdafx.h" at the top of the file.
- From the main menu select Build, Build Solution, to build the solution.
- Open a command prompt by selecting Start, Execute, and entering cmd. Go to the build directory for the project, and change into the Release directory.
- Run the application. You will receive an error: “cannot find mysqlcppconn.dll”.
- Copy mysqlcppconn.dll to the working directory or extend the PATH environment variable using SET PATH=%PATH%;C:\path\to\cpp. Alternatively, you can copy mysqlcppconn.dll to the Windows installation Directory, typically c:\windows.
Original Post : http://neodreamer-dev.tistory.com/282
Labels:
MYSQL
,
MySQL Connector/C++
,
MySQL Connector/C++ 컴파일 하기
,
TistoryOldPost
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment