I've installed OpenSSL to Windows 8, and did the necessary modifications to the OpenSSL library, without installing it as a native library. But I've a specific error message that I couldn't find it on internet.
1>------ Build started: Project: CryptoProject, Configuration: Debug Win32 ------
1> main.cpp
1>main.obj : error LNK2019: unresolved external symbol _BN_new referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _BN_bn2dec referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _BN_generate_prime referenced in function _main
1>C:\Users\...\...\...\Debug\EXAMPLE.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Hope you guys find something. So here it goes:
#include <iostream>
#include <string>
#include "openssl/bn.h"
using namespace std;
int main()
{
BIGNUM * q = BN_new();
BIGNUM * two = BN_new();
long int num_bits_q = 160;
long int num_bits_p = 1024;
BN_generate_prime(q, num_bits_q, 0, two, NULL,NULL,NULL);
cout << "q is: " << BN_bn2dec(q) << endl;
return 0;
}
I ran that code and it compiled successfully in visual studio 2012, I used OpenSSL-Win32. If OpenSSL-Win64 does not work use OpenSSL-Win32, I also had the same problem. Don't forget to include ssleay32.lib, I hope you know how to configure OpenSSl in visual studio.
Related
I've spent about two days now trying to get this to work but I still keep getting the same error with every method I do. I'm new to connecting MySQL to C++ so I'm a bit lost and every time I try to compile it, the thing spits out LNK2019 error. I'm using Visual Studio 2022.
#include <iostream>
#include <mysql.h>
using namespace std;
// DATABASE STUFF
struct connection_details {
const char* server, * user, * password, * database;
};
MYSQL* mysql_connection_setup(struct connection_details mysql_details) {
MYSQL* connection = mysql_init(NULL);
if (!(mysql_real_connect(connection, mysql_details.server, mysql_details.user, mysql_details.password, mysql_details.database, 0, NULL, 0))) {
cout << "Connection Error: " << mysql_error(connection) << endl;
exit(1);
}
return connection;
}
MYSQL_RES* mysql_execute_query(MYSQL* connection, const char* sql_query) {
if (mysql_query(connection, sql_query)) {
cout << "MYSQL Query Error: " << mysql_error(connection) << endl;
exit(1);
}
return mysql_use_result(connection);
}
// MAIN FUNCTION
int main(int argc, char const* argv[]) {
MYSQL* con;
MYSQL_RES* res;
MYSQL_ROW row;
struct connection_details mysql_db;
mysql_db.server = "localhost";
mysql_db.user = "root";
mysql_db.password = "tAblE4wTe3";
mysql_db.database = "test";
con = mysql_connection_setup(mysql_db);
res = mysql_execute_query(con, "select * from table1");
cout << "Displaying Database:\n" << endl;
while ((row = mysql_fetch_row(res)) != NULL) {
cout << row[0] << " | " << row[1] << " | " << row[2] << endl;
}
mysql_free_result(res);
mysql_close(con);
return 0;
}
Errors it shows:
1>------ Build started: Project: Test, Configuration: Debug x64 ------
1>main.obj : error LNK2019: unresolved external symbol mysql_error referenced in function "struct MYSQL * __cdecl mysql_connection_setup(struct connection_details)" (?mysql_connection_setup##YAPEAUMYSQL##Uconnection_details###Z)
1>main.obj : error LNK2019: unresolved external symbol mysql_init referenced in function "struct MYSQL * __cdecl mysql_connection_setup(struct connection_details)" (?mysql_connection_setup##YAPEAUMYSQL##Uconnection_details###Z)
1>main.obj : error LNK2019: unresolved external symbol mysql_real_connect referenced in function "struct MYSQL * __cdecl mysql_connection_setup(struct connection_details)" (?mysql_connection_setup##YAPEAUMYSQL##Uconnection_details###Z)
1>main.obj : error LNK2019: unresolved external symbol mysql_query referenced in function "struct MYSQL_RES * __cdecl mysql_execute_query(struct MYSQL *,char const *)" (?mysql_execute_query##YAPEAUMYSQL_RES##PEAUMYSQL##PEBD#Z)
1>main.obj : error LNK2019: unresolved external symbol mysql_use_result referenced in function "struct MYSQL_RES * __cdecl mysql_execute_query(struct MYSQL *,char const *)" (?mysql_execute_query##YAPEAUMYSQL_RES##PEAUMYSQL##PEBD#Z)
1>main.obj : error LNK2019: unresolved external symbol mysql_free_result referenced in function main
1>main.obj : error LNK2019: unresolved external symbol mysql_fetch_row referenced in function main
1>main.obj : error LNK2019: unresolved external symbol mysql_close referenced in function main
1>C:\Users\Administrator\Documents\Visual Studio 2022\C++ Projects\Test\x64\Debug\Test.exe : fatal error LNK1120: 8 unresolved externals
1>Done building project "Test.vcxproj" -- FAILED.
These are the include/library folder locations:
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\libbinlogevents
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\libbinlogstandalone
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\libchangestreams
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\libmysql
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\libservices
C:\Program Files\MySQL\Connector C++ 8.0\lib64\vs14
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\include
C:\Program Files\MySQL\Connector C++ 8.0\include
I've tried looking it up, and every forum, video, etc. that I try using to resolve doesn't work. I'm not sure if it's a 32-bit or 64-bit issue, though I don't think it is since all files point to 64-bit folders. I'm thinking it's something in my code but I'm very new to this so I can't really pinpoint it. Any help would be appreciated.
EDIT: I managed to solve it, just started the project from scratch and followed the visual studio docs and this video.
I want to use the Eclipse Paho MQTT C library in a simple C++ program. For the library i used the the pre-build binaries for windows - see https://projects.eclipse.org/projects/technology.paho/downloads
C client for Windows 1.3.0 - 64 bit
I found the exact same issue in this talk LNK2019 error when compiling a Visual C++ Win32 project with Eclipse Paho MQTT.
For linkage in include I have the following setting:
C/C++ - Additional include: xxx\paho\eclipse-paho-mqtt-c-win64-1.3.0\include
Linker - additional Additional Library Directories
Linker - input - additional dependencies:
eclipse-paho-mqtt-c-win64-1.3.0\lib\paho-mqtt3cs.lib
eclipse-paho-mqtt-c-win64-1.3.0\lib\paho-mqtt3c.lib
eclipse-paho-mqtt-c-win64-1.3.0\lib\paho-mqtt3a.lib
eclipse-paho-mqtt-c-win64-1.3.0\lib\paho-mqtt3as.lib
My code is as follows:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern "C" {
#include <MQTTClient.h>
#include <MQTTClientPersistence.h>
}
#define ADDRESS "xxx"
#define CLIENTID "ExampleClientSub"
#define TOPIC "xxx"
#define PAYLOAD "Hello World!"
#define QOS 1
#define TIMEOUT 10000L
int main()
{
MQTTClient client;
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
int rc;
int ch;
MQTTClient_create(&client, ADDRESS, CLIENTID,
MQTTCLIENT_PERSISTENCE_NONE, NULL);
conn_opts.keepAliveInterval = 20;
conn_opts.cleansession = 1;
conn_opts.username = "roman.busse";
conn_opts.password = "VojUriLKhOsmzUJQ1lld";
MQTTClient_setCallbacks(client, NULL, connlost, msgarrvd, delivered);
if ((rc = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS)
{
printf("Failed to connect, return code %d\n", rc);
exit(EXIT_FAILURE);
}
printf("Subscribing to topic %s\nfor client %s using QoS%d\n\n"
"Press Q<Enter> to quit\n\n", TOPIC, CLIENTID, QOS);
MQTTClient_subscribe(client, TOPIC, QOS);
do
{
ch = getchar();
} while (ch != 'Q' && ch != 'q');
MQTTClient_unsubscribe(client, TOPIC);
MQTTClient_disconnect(client, 10000);
MQTTClient_destroy(&client);
return 0;
}
So like you can see i said to the compiler: "Yes this is a C lib". But all in all I get the same LNK2019 errors...
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _MQTTClient_setCallbacks
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_create referenced
in function _main paho_test C:\Users\rtreiber\documents\visual studio
2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_connect
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_disconnect
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_subscribe
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_unsubscribe
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_freeMessage
referenced in function "int __cdecl msgarrvd(void *,char *,int,struct
MQTTClient_message *)"
(?msgarrvd##YAHPAXPADHPAUMQTTClient_message###Z) paho_test C:\Users\rtreiber\documents\visual
studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_free referenced
in function "int __cdecl msgarrvd(void *,char *,int,struct
MQTTClient_message *)"
(?msgarrvd##YAHPAXPADHPAUMQTTClient_message###Z) paho_test C:\Users\rtreiber\documents\visual
studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_destroy
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1 Error LNK1120 9
unresolved externals paho_test C:\Users\rtreiber\documents\visual
studio 2017\Projects\paho_test\Debug\paho_test.exe 1
So any ideas?
This question already has answers here:
error LNK2019: unresolved external symbol _WinMain#16 referenced in function ___tmainCRTStartup
(13 answers)
Closed 9 years ago.
I get the following error Error 'LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt' when I compile my code using Win32 Console Application.
I tried fixing it my going into Projects -> Properties -> General -> Linker -> Enable Incremental Linking and I changed it from "Yes" to No (/INCREMENTAL:NO) and then I tried to debug my code again but got another error message :
1>------ Build started: Project: Someproject, Configuration: Debug Win32 ------
1>project1.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain#16 referenced in function ___tmainCRTStartup
1>c:\users\anne\documents\visual studio 2010\Projects\Someproject\Debug\Someproject.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
How can I fix it?
#include <Windows.h>
#include <process.h>
#include <stdio.h>
#include <math.h>
volatile int counter = 0;
int isPrime(int n)
{
for(int i = 2; i < (int)(sqrt((float)n) + 1.0) ; i++) {
if (n % i == 0) return 0;
}
return 1;
}
unsigned int __stdcall mythread(void*)
{
char* s;
while (counter < 25) {
int number = counter++;
s = "No";
if(isPrime(number)) s = "Yes";
printf("Thread %d value = %d is prime = %s\n",
GetCurrentThreadId(), number, s);
}
return 0;
}
int main(int argc, char* argv[])
{
HANDLE myhandleA, myhandleB;
myhandleA = (HANDLE)_beginthreadex(0, 0, &mythread, (void*)0, 0, 0);
myhandleB = (HANDLE)_beginthreadex(0, 0, &mythread, (void*)0, 0, 0);
WaitForSingleObject(myhandleA, INFINITE);
WaitForSingleObject(myhandleB, INFINITE);
CloseHandle(myhandleA);
CloseHandle(myhandleB);
getchar();
system("pause");
return 0;
}
The basic problem is that you somehow specified "windows app" in your project settings. You want "console app" instead.
Windows apps use "WinMain()"; console apps use "main()".
Look at this link for details:
error LNK2019: unresolved external symbol _WinMain#16 referenced in function ___tmainCRTStartup
See also:
Building Console Applications
EDITED:
My Problem is the errors at the bottom of this post.
Heres my additional include directories
C:\Program Files\boost
C:\Program Files\MySQL\MySQL Connector C++ 1.1.3\include
C:\Program Files\MySQL\MySQL Server 5.6\include
Additional Library Directories
C:\Program Files\MySQL\MySQL Server 5.6\lib
C:\Program Files\MySQL\Connector C++ 1.1.2\lib\opt
Additional Dependencies
libmysql.lib
mysqlcppconn-static.lib
Heres my code
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
#include <stdlib.h>
#include <Windows.h>
#include <mysql.h>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#define host "localhost"
#define username "root"
#define password "root"
#define database "tests"
int main()
{
MYSQL* conn;
conn = mysql_init( NULL );
if( conn )
{
mysql_real_connect( conn, host, username, password, database, 0, NULL, 0 );
}
MYSQL_RES* res_set;
MYSQL_ROW row;
unsigned int i;
mysql_query( conn, "SELECT * FROM tbl_clients WHERE id = 1" );
res_set = mysql_store_result( conn );
unsigned int numrows = mysql_num_rows( res_set );
if( numrows )
{
row = mysql_fetch_row( res_set );
if( row != NULL )
{
cout << "Client ID : " << row[0] << endl;
cout << "Client Name: " << row[1] << endl;
}
}
if( res_set )
{
mysql_free_result( res_set );
}
if( conn )
{
mysql_close( conn );
}
return 0;
}
These are the errors I get
1>------ Build started: Project: okay, Configuration: Debug Win32 ------
1>welp.obj : error LNK2019: unresolved external symbol _mysql_num_rows#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_init#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_real_connect#32 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_query#8 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_store_result#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_free_result#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_fetch_row#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_close#4 referenced in function _main
1>C:\Users\Damian\documents\visual studio 2012\Projects\okay\Debug\okay.exe : fatal error LNK1120: 8 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Please help, This project is due in about 48 hours for my class, and I've spent so much time trying to figure this out.
Thanks
respectfully, your last two questions are compiler/linker questions. I understand your frustration, as I knew how to code early but knew nothing about compilers/linkers. When you get a moment take some time to read about:
headers
binary vs object file
libraries / shared object
compiler
linker
function mangling (C vs C++)
To answer your question, I am guessing you're doing this in Microsoft Visual Studio:
You need to go to Project Properties and set Additional Library Paths (i see you did that from your last post)
You need to specify the library, I'm going out on a limb here and assuming it will mysql.lib ... There's an "Additional Library" input somewhere in the Linker section, you'll be able to identify it because kernel32.lib will be int it. Add the mysql.lib to that section. Confirm the name by going to the mysql folder which holds the binaries.
Make sure you're using the static library, the .dll will give you new issues that you don't need to worry about. This is usually achieved by setting the correct library directory. Many c++ libraries will ship with precompiled "Static" and "Dynamic" folders containing the correct libraries.
This is error is happening due to linker problem. The linker is not able to find the required static or dynamic libraries (mysql.lib,mysqlcppconn-static.lib,libmysql.dll and libmysql.lib). The additional lib setting is wrong. Check this site give the path correctly Building MySQL Connector/C++ Windows Applications with Microsoft Visual Studio
I have read all the previous replies or solutions for the same linker problem. I understand that the Linker is unable to access the library file that has the functions defined but still I have no luck in solving it!
The errors:
1>trial_12th.obj : error LNK2019: unresolved external symbol _viStatusDesc#12 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viClose#4 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viRead#16 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viWrite#16 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viOpen#20 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viOpenDefaultRM#4 referenced in function _main
1>C:\Users\41kchoudhary\Documents\Visual Studio 2010\Projects\trial_12th\Debug\trial_12th.exe : fatal error LNK1120: 6 unresolved externals
I am trying to send and receive data from a mixed-signal oscilloscope. In doing so I am required to write a .cpp file using the pre-defined commands/functions defined using Microsoft Visual Studio C++. I have read the user manual for using these commands, and I also have the header files and libraries required to implement it.
I am using the following code:
#include <visa.h>
#include "stdafx.h"
#include <stdio.h>
#include <memory.h>
int main(int argc, char* argv[])
{
ViSession rm = VI_NULL, vi = VI_NULL;
ViStatus status;
ViChar buffer[256];
ViUInt32 retCnt;
// Open a default session
status = viOpenDefaultRM(&rm);
if (status < VI_SUCCESS) goto error;
// Open the GPIB device at primary address 1, GPIB board 8
status = viOpen(rm, "USB::0x0699::0x0377::C011104::INSTR", VI_NULL, VI_NULL,
&vi);
if (status < VI_SUCCESS) goto error;
// Send an ID query.
status = viWrite(vi, (ViBuf) "*idn?", 5, &retCnt);
if (status < VI_SUCCESS) goto error;
// Clear the buffer and read the response
memset(buffer, 0, sizeof(buffer));
status = viRead(vi, (ViBuf) buffer, sizeof(buffer), &retCnt);
if (status < VI_SUCCESS) goto error;
// Print the response
printf("id: %s\n", buffer);
// Clean up
viClose(vi); // Not needed, but makes things a bit more
// understandable
viClose(rm); // Closes resource manager and any sessions
// opened with it
return 0;
error:
// Report error and clean up
viStatusDesc(vi, status, buffer);
fprintf(stderr, "failure: %s\n", buffer);
if (rm != VI_NULL) {
viClose(rm);
}
return 1;
}
You need to add either visa32.lib or visa64.lib to your linker settings.
One way to do that is to use a pragma in your compiler source file:
#pragma comment(lib,"visa32.lib")
If it is still not found then adjust your lib paths in your IDE or include the full path in the pragma.
I had the same issue. I figured out that you have to add visa32.lib in additional dependencies under the linker properties of your project
Go to your
project properties -> Linker -> Additional Dependencies-> Click Down Arrow -> "Edit -> Type visa32.lib
Click Ok, Ok