database connection checking in c++ program - c++

I am trying to connect a database with the c++ program using OCILIB interface.
my program is:-
#include "ocilib.h"
int main(int argc, char *args[])
{
OCI_Connection *cn;
if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT))
cout << "connection failed";
cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
if (cn != NULL)
{
cout <<OCI_GetVersionServer(cn);
cout <<"Server major version : %i\n"<< OCI_GetServerMajorVersion(cn);
cout <<"Server minor version : %i\n"<<OCI_GetServerMinorVersion(cn);
cout <<"Server revision version : %i\n"<< OCI_GetServerRevisionVersion(cn);
cout <<"Connection version : %i\n"<< OCI_GetVersionConnection(cn);
OCI_ConnectionFree(cn);
}
OCI_Cleanup();
}
this code running in MSVisualstudio2015, I downloaded all OCI packages and set according to my environment..
i put linker path and additional include header files in project properties.
but when i building the application it shows.
1>------ Build started: Project: Testdatabase, Configuration: Debug x64 ------
1> Testing.cpp
1>Testing.obj : error LNK2019: unresolved external symbol OCI_Initialize
referenced in function main
1>Testing.obj : error LNK2019: unresolved external symbol OCI_Cleanup
referenced in function main
1>Testing.obj : error LNK2019: unresolved external symbol
OCI_ConnectionCreate referenced in function main
1>Testing.obj : error LNK2019: unresolved external symbol
OCI_ConnectionFree referenced in function main
1>Testing.obj : error LNK2019: unresolved external symbol
OCI_GetVersionServer referenced in function main
1>Testing.obj : error LNK2019: unresolved external symbol
OCI_GetServerMajorVersion referenced in function main
1>Testing.obj : error LNK2019: unresolved external symbol
OCI_GetServerMinorVersion referenced in function main
1>Testing.obj : error LNK2019: unresolved external symbol
OCI_GetServerRevisionVersion referenced in function main
1>Testing.obj : error LNK2019: unresolved external symbol
OCI_GetVersionConnection referenced in function main
1>c:\XXXXX\XXXXXX\documents\visual studio
2015\Projects\Testdatabase\x64\Debug\Testdatabase.exe : fatal error
LNK1120: 9 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I read some documentations about this problem , but i am not able to solve this problem , give me any solution..

You need to copy ociliba.dll from the ocilib archive (under lib32|64 folder) to the folder where your executable is generated.

Related

msvcrtd.lib(exe_main.obj) : error LNK2019: unresolved external symbol main referenced in function

I am using gradle to build my c++ library
I added this line to build.gradle file
linkTask.linkerArgs.add("msvcrt${linkTask.name.toLowerCase().contains('debug') ? 'd' : ''}.lib")
Error :
> Task :psfe:linkDebugWindows FAILED
msvcrtd.lib(exe_main.obj) : error LNK2019: unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main##YAHXZ)
Caching disabled for task ':psfe:linkDebugWindows' because:
D:\a\piv\piv\psfe\build\lib\main\debug\windows\psfe.dll : fatal error LNK1120: 1 unresolved externals
Build cache is disabled
How can I solve this error ?

Visual Studio Community 2017 linker problems - MariaDB

Its my first foray into messing with DB's in programming (specifically MariaDB) in Visual Studio and am not having much luck. It looks like I have configured external linking incorrectly however I am staring at my settings and just not seeing the error. Its probably going to be obvious to more experienced coders out there but I can't see the forest because of the trees.
I have tried compiling in both x86 and 64bit with their respective libraries. I've only included the x86 settings below but they are identical APART from pointing to "program files" instead of "program files x86"
My code is quite simple at the moment:
#include "stdafx.h"
#include <mysql.h>
int main()
{
MYSQL* temp;
temp = mysql_init(NULL);
return 0;
}
but when I try to compile I get the following output.
1>------ Build started: Project: test, Configuration: Debug Win32 ------
1>test.cpp
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>mariadbclient.lib(mariadb_lib.obj) : error LNK2019: unresolved external symbol __imp__ntohs#4 referenced in function _mysql_once_init
1>mariadbclient.lib(mariadb_lib.obj) : error LNK2019: unresolved external symbol __imp__getservbyname#8 referenced in function _mysql_once_init
1>mariadbclient.lib(mariadb_lib.obj) : error LNK2019: unresolved external symbol __imp__PathRemoveExtensionA#4 referenced in function _mysql_optionsv
1>mariadbclient.lib(mariadb_lib.obj) : error LNK2019: unresolved external symbol __imp__PathStripPathA#4 referenced in function _mysql_optionsv
1>mariadbclient.lib(ma_init.obj) : error LNK2019: unresolved external symbol __imp__WSAStartup#8 referenced in function _my_win_init
1>mariadbclient.lib(ma_init.obj) : error LNK2019: unresolved external symbol __imp__WSACleanup#0 referenced in function _ma_end
1>mariadbclient.lib(ma_pvio.obj) : error LNK2019: unresolved external symbol __imp__WSAGetLastError#0 referenced in function _ma_pvio_read_async
1>mariadbclient.lib(mariadb_async.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError#0
1>mariadbclient.lib(pvio_socket.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError#0
1>mariadbclient.lib(ma_default.obj) : error LNK2019: unresolved external symbol __imp__PathRemoveFileSpecA#4 referenced in function _get_default_configuration_dirs
1>mariadbclient.lib(mariadb_async.obj) : error LNK2019: unresolved external symbol __imp__connect#12 referenced in function _my_connect_async
1>mariadbclient.lib(pvio_socket.obj) : error LNK2001: unresolved external symbol __imp__connect#12
1>mariadbclient.lib(mariadb_async.obj) : error LNK2019: unresolved external symbol __imp__getsockopt#20 referenced in function _my_connect_async
1>mariadbclient.lib(pvio_socket.obj) : error LNK2001: unresolved external symbol __imp__getsockopt#20
1>mariadbclient.lib(pvio_socket.obj) : error LNK2019: unresolved external symbol ___WSAFDIsSet#8 referenced in function _pvio_socket_wait_io_or_timeout
1>mariadbclient.lib(pvio_socket.obj) : error LNK2019: unresolved external symbol __imp__bind#12 referenced in function _pvio_socket_connect
1>mariadbclient.lib(pvio_socket.obj) : error LNK2019: unresolved external symbol __imp__closesocket#4 referenced in function _pvio_socket_connect
1>mariadbclient.lib(pvio_socket.obj) : error LNK2019: unresolved external symbol __imp__ioctlsocket#12 referenced in function _pvio_socket_blocking
1>mariadbclient.lib(pvio_socket.obj) : error LNK2019: unresolved external symbol __imp__recv#16 referenced in function _pvio_socket_async_read
1>mariadbclient.lib(pvio_socket.obj) : error LNK2019: unresolved external symbol __imp__select#20 referenced in function _pvio_socket_wait_io_or_timeout
1>mariadbclient.lib(pvio_socket.obj) : error LNK2019: unresolved external symbol __imp__send#16 referenced in function _pvio_socket_async_write
1>mariadbclient.lib(pvio_socket.obj) : error LNK2019: unresolved external symbol __imp__setsockopt#20 referenced in function _pvio_socket_fast_send
1>mariadbclient.lib(pvio_socket.obj) : error LNK2019: unresolved external symbol __imp__shutdown#8 referenced in function _pvio_socket_close
1>mariadbclient.lib(pvio_socket.obj) : error LNK2019: unresolved external symbol __imp__socket#12 referenced in function _pvio_socket_connect
1>mariadbclient.lib(pvio_socket.obj) : error LNK2019: unresolved external symbol __imp__WSASetLastError#4 referenced in function _pvio_socket_wait_io_or_timeout
1>mariadbclient.lib(pvio_socket.obj) : error LNK2019: unresolved external symbol __imp__getaddrinfo#16 referenced in function _pvio_socket_connect
1>mariadbclient.lib(pvio_socket.obj) : error LNK2019: unresolved external symbol __imp__freeaddrinfo#4 referenced in function _pvio_socket_connect
1>mariadbclient.lib(ma_schannel.obj) : error LNK2019: unresolved external symbol __imp__CryptAcquireContextA#20 referenced in function _ma_schannel_load_private_key
1>mariadbclient.lib(ma_schannel.obj) : error LNK2019: unresolved external symbol __imp__CryptReleaseContext#8 referenced in function _ma_schannel_load_private_key
1>mariadbclient.lib(ma_schannel.obj) : error LNK2019: unresolved external symbol __imp__CryptDestroyKey#4 referenced in function _ma_schannel_load_private_key
1>mariadbclient.lib(ma_schannel.obj) : error LNK2019: unresolved external symbol __imp__CryptImportKey#24 referenced in function _ma_schannel_load_private_key
1>d:\nikuya\documents\visual studio 2017\Projects\test\Debug\test.exe : fatal error LNK1120: 27 unresolved externals
1>Done building project "test.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
My settings are below -
VC++ Directories -> Include Directories -> C:\Program Files %28x86%29\MariaDB\MariaDB Connector C\include\mysql
VC++ Directories -> Include Directories -> C:\Program Files %28x86%29\MariaDB\MariaDB Connector C\include\mysql\include
VC++ Directories -> Library Directories -> C:\Program Files %28x86%29\MariaDB\MariaDB Connector C\lib
VC++ Directories -> Library Directories -> C:\Program Files %28x86%29\MariaDB\MariaDB Connector C\lib\plugin
C++ Directories -> Addition Include Directories -> C:\Program Files %28x86%29\MariaDB\MariaDB Connector C\include\mysql
C++ Directories -> Addition Include Directories -> C:\Program Files %28x86%29\MariaDB\MariaDB Connector C\include
Linker -> General -> Addition Library Directories -> C:\Program Files %28x86%29\MariaDB\MariaDB Connector C\lib\plugin
Linker -> General -> Addition Library Directories -> C:\Program Files %28x86%29\MariaDB\MariaDB Connector C\lib
Linker -> Additional Dependancies -> mariadbclient.lib
Linker -> Additional Dependancies -> libmariadb.lib
Any help would be appreciated and please ask if any further info is needed.
note: I also tried including windows.h out of desperation but no dice.
The key line here is:
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
You are attempting to use a library which is incompatible with libcmt which is the multithreaded c run time library.
It is likely that you are compiling with a different switch (often /MD or /MT) somewhere to what was used to build the mariadb libs.
See here for more info:
https://msdn.microsoft.com/en-us/library/aa267384(v=vs.60).aspx

VC++ Library Miss while compiling application? unzip.obj : error LNK2019

I try to compile VC++ application and get the error message as below. Is there anyone who know what the library I may be missing? Any advice & suggestion are appreciated.
My Environment:
VC++ 2010
zlib-1.2.8
boost_1_57_0
icu
1>------ Build started: Project: paloserver, Configuration: Debug Win32 ------
1> Creating library C:/Users/a992788/Virtual Machines/Documents/Application/Palo/Palo 3.x Source Code/palo-code-546/molap/server/5.1/SourceCode/Debug/paloserver.lib and object C:/Users/a992788/Virtual Machines/Documents/Application/Palo/Palo 3.x Source Code/palo-code-546/molap/server/5.1/SourceCode/Debug/paloserver.exp
1>unzip.obj : error LNK2019: unresolved external symbol _inflateInit2_ referenced in function _unzOpenCurrentFile3
1>unzip.obj : error LNK2019: unresolved external symbol _inflate referenced in function _unzReadCurrentFile
1>unzip.obj : error LNK2019: unresolved external symbol _crc32 referenced in function _unzReadCurrentFile
1>zip.obj : error LNK2001: unresolved external symbol _crc32
1>unzip.obj : error LNK2019: unresolved external symbol _inflateEnd referenced in function _unzCloseCurrentFile
1>zip.obj : error LNK2019: unresolved external symbol _get_crc_table referenced in function _zipOpenNewFileInZip4_64
1>zip.obj : error LNK2019: unresolved external symbol _deflateInit2_ referenced in function _zipOpenNewFileInZip4_64
1>zip.obj : error LNK2019: unresolved external symbol _deflate referenced in function _zipWriteInFileInZip
1>zip.obj : error LNK2019: unresolved external symbol _deflateEnd referenced in function _zipCloseFileInZipRaw64
1>C:\Users\a992788\Virtual Machines\Documents\Application\Palo\Palo 3.x Source Code\palo-code-546\molap\server\5.1\SourceCode\Debug\paloserver.dll : fatal error LNK1120: 8 unresolved externals
Add reference to the zdll.lib in your source.
#pragma comment (lib, "zdll.lib")

Linking Error between matlab R2013a and MS VC++ 2013

I am writing a BCI game application in VC++ and require to implement Common Spatial Pattern Filtering (CSP) for feature extraction. Due to the hefty coding involved, I prefer to use an existing CSP Matlab function that I have. I followed the steps as given in here. However, I am getting the following Link error message:
1>------ Build started: Project: Test4, Configuration: Debug Win32 ------
1>test.obj : error LNK2019: unresolved external symbol _mxGetScalar referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _mxDestroyArray referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _mxCreateDoubleScalar referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _engEvalString referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _engOpen referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _engClose referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _engGetVariable referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _engPutVariable referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _engOutputBuffer referenced in function _main
1>D:\Test4\Debug\Test4.exe : fatal error LNK1120: 9 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Could anyone please help me fix the problem? Any comments would be appreciated. Thanks in advance.
As I said in the referred post, you have to keep the platforms consistent:
The platforms of MATLAB and VC++ compile platform must be the same, i.e. Win32/x86 VC++ compile platform can only use x86 MATLAB and x64 VC++ compile platform can only use x64 MATLAB.
You're using MATLAB x64, thus you have to build your VC project in x64 too.

A slight issue with GLFW (x64)

I am currently working on converting some of my applications to C++, and for that i have decided to use openGL, as ive got some experience with it from other platforms.
But getting this to compile in x64 seems to be quite a lot of hassle. To check if my linking stuff is working i am just trying to compile this tutorial:
http://www.opengl-tutorial.org/beginners-tutorials/tutorial-1-opening-a-window/
But as you can see, i failed miserably. I have downloaded and installed:
freeglut
GLM
GLFW
GLEW
The issue clearly seems to lay within GLFW. I am using Visual express c++ 2010.
I installed GLFW like this:
GLFW.dll (System32)
glfw.h (C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\gl)
GLFW.lib (C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64)
GLFWDLL.lib (C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64)
My linker:
kernel32.lib;glu32.lib;glew32.lib;GLFW.lib;GLFWDLL.lib;opengl32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
Output:
1>------ Build started: Project: Spacecraft, Configuration: Debug x64 ------
1> Main.cpp
1>Main.obj : error LNK2019: unresolved external symbol __imp_glfwGetWindowParam referenced in function main
1>Main.obj : error LNK2019: unresolved external symbol __imp_glfwGetKey referenced in function main
1>Main.obj : error LNK2019: unresolved external symbol __imp_glfwSwapBuffers referenced in function main
1>Main.obj : error LNK2019: unresolved external symbol __imp_glfwEnable referenced in function main
1>Main.obj : error LNK2019: unresolved external symbol __imp_glfwSetWindowTitle referenced in function main
1>Main.obj : error LNK2019: unresolved external symbol __imp_glfwTerminate referenced in function main
1>Main.obj : error LNK2019: unresolved external symbol __imp_glfwOpenWindow referenced in function main
1>Main.obj : error LNK2019: unresolved external symbol __imp_glfwOpenWindowHint referenced in function main
1>Main.obj : error LNK2019: unresolved external symbol __imp_glfwInit referenced in function main
1>c:\users\leif andreas\documents\visual studio 2010\Projects\Spacecraft\x64\Debug\Spacecraft.exe : fatal error LNK1120: 9 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
And finally, my includes:
// Include standard headers
#include <stdio.h>
#include <stdlib.h>
// Include GLEW
#include <gl/glew.h>
#include <gl/glut.h>
// Include GLFW
#include <gl/glfw.h>
// Include GLM
#include <glm/glm.hpp>
using namespace glm;