Unresolved External Symbol Error C++ While Adding New Library - c++

I am trying to use Blaze C++ Library so I downloaded this library and successfully added to my project and used basic functionalities , but for extra functionalities I have to add BLAS and LAPACK library too. so i downloaded these packages .lib and .dll files. I did these:
1 - Project >> Linker >> General >> Additional Library Directories : I defined the path contains .dll files
2 - Project >> Linker >> Input >> Additional Dependencies : I defined the path contains .lib files
but when I try below code I receive some errors:
Code
#include <iostream>
#include <blaze/Math.h>
using namespace blaze;
using namespace std;
int main()
{
StaticMatrix<double,100,100> A;
for (size_t i = 0; i < 100; i++)
{
for (size_t j = 0; j < 100; j++)
{
A(i, j) = i + j;
}
}
blaze::DynamicMatrix<double, blaze::rowMajor> L, U, P;
lu(A, L, U, P);
}
Errors
1 - Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol dgetrf_ referenced in function "void __cdecl
blaze::getrf(int,int,double *,int,int *,int *)" (?getrf#blaze##YAXHHPEANHPEAH1#Z) MyProject
D:\C++\MyProject \MyProject \MyProject.obj 1
2 - Severity Code Description Project File Line Suppression State
Error LNK1120 1 unresolved externals MyProject D:\C++\MyProject\x64\Debug\MyProject.exe 1
what should have I do ?

Related

Linker error for adding static library

I am following a tutorial here for creating a static library and using it for another project. So I want to create a .lib file and use it for another project.
Static library project:
MyMathLib.h
#define PI 3.1415;
double PowerOf2(double UserNumber);
double PowerOf3(double UserNumber);
double CircleArea(double UserRadius);
double CircleCircum(double UserRadius);
MyMathLib.cpp
#include "stdafx.h"
#include "MyMathLib.h"
double PowerOf2(double UserNumber) { return UserNumber * UserNumber; }
double PowerOf3(double UserNumber) { return UserNumber * UserNumber * UserNumber; }
double CircleArea(double UserRadius) { return UserRadius * UserRadius * PI; }
double CircleCircum(double UserRadius) { return 2 * UserRadius * PI; }
For the second project, I have done the following:
Add the MyMathLib vc project
Common Properties -> References -> Add New Reference
C/C++ -> General -> Additional Include Directories.
This is the C file that tries to call the library:
MyApps1.c
#include <stdio.h>
#include "MyMathLib.h"
int main()
{
double p2 = 10.0;
double radius = 4.0;
printf("The number %.2f to the power of 2 is %.2f. \n", p2, PowerOf2(p2));
printf("A circle with a radius of %.2f, the area is %.2f. \n", radius, CircleArea(radius));
return 0;
}
The error I am getting is:
1>------ Build started: Project: MyApps1, Configuration: Debug Win32 ------
1>MyApps1.obj : error LNK2019: unresolved external symbol _PowerOf2 referenced in function _main
1>MyApps1.obj : error LNK2019: unresolved external symbol _CircleArea referenced in function _main
1>c:\users\bandika\documents\visual studio 2013\Projects\MyApps1\Debug\MyApps1.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
So there is a linking error somewhere. I have tried going to MyApps1 Properties -> Linker -> Input -> Additional Dependencies but I don't think I can add the .lib file for MyMathLib. Any idea what I'm missing?
Its related to linking of your static lib with the second project.
I don't see any problem in adding your generated static library name in "Configuration Properties -> Linker -> Input -> Additional Dependencies".
It should solve the linking problem.
Are you facing any other problem after using this option?
You do not have the second file added to the project in the VS.

Difficulty using Protobuf 3.2 in C++

I'm trying to use Protobuf in C++, but having trouble getting it to do anything meaningful. I'm using Visual Studio 2015.
I built the protobuf library. I'm using the latest version from github.
I have created a .proto file as such:
syntax = "proto3";
package Networking;
message Robot{
message KinematicLinkProto {
string name = 1;
float x_pos = 2;
float y_pos = 3;
float z_pos = 4;
float roll = 5;
float pitch = 6;
float yaw = 7;
float x_scale = 8;
float y_scale = 9;
float z_scale = 10;
}
repeated KinematicLinkProto links = 1;
}
I compile this, and try to add it to a project:
#include "Robot.pb.h"
int main(int argc, char **argv)
{
Networking::Robot robot_message;
return 0;
}
My linker links libprotobuf.lib. I am building it as /MD and libprotobuf is built as /MD.
For some reason, this simple program has the following two linker errors:
Error LNK2019 unresolved external symbol "private: static bool google::protobuf::io::CodedOutputStream::default_serialization_deterministic_" (?default_serialization_deterministic_#CodedOutputStream#io#protobuf#google##0_NA) referenced in function "public: virtual unsigned char * __cdecl Networking::Robot::SerializeWithCachedSizesToArray(unsigned char *)const " (?SerializeWithCachedSizesToArray#Robot#Networking##UEBAPEAEPEAE#Z)
Error LNK2019 unresolved external symbol "class google::protobuf::internal::ExplicitlyConstructed<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > google::protobuf::internal::fixed_address_empty_string" (?fixed_address_empty_string#internal#protobuf#google##3V?$ExplicitlyConstructed#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###123#A) referenced in function "protected: void __cdecl google::protobuf::internal::RepeatedPtrFieldBase::Clear<class google::protobuf::RepeatedPtrField<class Networking::Robot_KinematicLinkProto>::TypeHandler>(void)" (??$Clear#VTypeHandler#?$RepeatedPtrField#VRobot_KinematicLinkProto#Networking###protobuf#google###RepeatedPtrFieldBase#internal#protobuf#google##IEAAXXZ)
I'm very confused - this is a very simple program. What could I possibly be doing wrong?
EDIT: A colleague compiled proto 3001000. This version does seem to work. I'm curious as to what about 3002000 breaks everything.
If you are using DLL, use
#define PROTOBUF_USE_DLLS

CUDA and C++ simple project

I am trying to create a CUDA + C++ project. Basically a .cpp project that calls for some CUDA kernel. So I simply followed the example here, which basically adds two vectors. The kernel does the summation job:
http://blog.norture.com/2012/10/gpu-parallel-programming-in-vs2012-with-nvidia-cuda/
Here is the code,
#include <iostream>
#include "cuda_runtime.h"
#include "cuda.h"
#include "device_launch_parameters.h"
using namespace std;
__global__ void saxpy(int n, float a, float *x, float *y)
{
int i = blockIdx.x*blockDim.x + threadIdx.x;
if (i < n) y[i] = a*x[i] + y[i];
}
int main(void)
{
int N = 1<<20;
float *x, *y, *d_x, *d_y;
x = (float*)malloc(N*sizeof(float));
y = (float*)malloc(N*sizeof(float));
cudaMalloc(&d_x, N*sizeof(float));
cudaMalloc(&d_y, N*sizeof(float));
for (int i = 0; i < N; i++) {
x[i] = 1.0f;
y[i] = 2.0f;
}
cudaMemcpy(d_x, x, N*sizeof(float), cudaMemcpyHostToDevice);
cudaMemcpy(d_y, y, N*sizeof(float), cudaMemcpyHostToDevice);
// Perform SAXPY on 1M elements
saxpy<<<(N+255)/256, 256>>>(N, 2.0, d_x, d_y);
cudaMemcpy(y, d_y, N*sizeof(float), cudaMemcpyDeviceToHost);
float maxError = 0.0f;
for (int i = 0; i < N; i++)
maxError = max(maxError, abs(y[i]-4.0f));
cout << "Max error: " << maxError;
}
When I built I got this error:
1>------ Rebuild All started: Project: CUDATest001, Configuration: Debug x64 ------
1> CUDATestZeroZeroOne.cpp
1>CUDATestZeroZeroOne.obj : error LNK2001: unresolved external symbol threadIdx
1>CUDATestZeroZeroOne.obj : error LNK2001: unresolved external symbol blockIdx
1>CUDATestZeroZeroOne.obj : error LNK2001: unresolved external symbol blockDim
1>D:\Projects\CUDATest001\x64\Debug\CUDATest001.exe : fatal error LNK1120: 3 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
If the line saxpy<<<(N+255)/256, 256>>>(N, 2.0, d_x, d_y); is commented out, then this error appeared:
1>------ Rebuild All started: Project: CUDATest001, Configuration: Debug x64 ------
1> CUDATestZeroZeroOne.cpp
1>CUDATestZeroZeroOne.obj : error LNK2001: unresolved external symbol threadIdx
1>CUDATestZeroZeroOne.obj : error LNK2001: unresolved external symbol blockIdx
1>CUDATestZeroZeroOne.obj : error LNK2001: unresolved external symbol blockDim
1>D:\Projects\CUDATest001\x64\Debug\CUDATest001.exe : fatal error LNK1120: 3 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
I am using vs2012 + CUDA 5.5. I started with a empty C++ win32 console project, added a .cpp file which includes all the code above. I am not even sure at this point should it be a .cu or a .cpp file?
Anyone has any idea how to make this work? Thanks.
In the context menu for your project, click Build Customizations. Turn on the CUDA 5.5 target.
In the context menu for your .cpp file, click Rename and rename it to .cu.
In the context menu for your .cu file (that you just renamed), select Properties. Then go to General and make sure Item Type is set to CUDA C/C++.
Rebuild.
When you start a new CUDA project, you can select Templates > NVIDIA > CUDA 5.5 > CUDA 5.5 Runtime to get a project that should compile without any modifications.

MSVS 2012 Express - Boost - Linker error LNK2019

I'm trying to build a project that's using some functionality of the file system part of the Boost library and I keep getting linker errors.
I followed the Boost documentation to build it and it built successfully and then moved all the lib files from the stage directory to C:/boost/lib and the hpp files to C:/boost/include. I'm using Microsoft Visual Studio 2012 Express Edition. I've made sure to add the files (libboost_filesystem-vc110-mt-1_54.lib and libboost_system-vc110-mt-1_54.lib) in the properties page to the files that need to be linked in (I also tried it with the #pragma's explicitly). I tried both the .lib files containing gd and the ones that dont (the debugging ones and the ones that aren't for debugging).
My question is, how do I fix this? Did I build the files wrong? Did I specify some sort of linker property wrong?
Here's the errors (I omitted some to keep it short, if needed I can add them all):
Error 1 error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category#system#boost##YAAEBVerror_category#12#XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'native_ecat''(void)" (??__Enative_ecat#system#boost##YAXXZ) C:\Visual Studio 2012 Projects\MMS_Solution\MMS_Prj_FindFile\MMS_Prj_FindFile.obj MMS_Prj_FindFile
Error 2 error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category#system#boost##YAAEBVerror_category#12#XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'errno_ecat''(void)" (??__Eerrno_ecat#system#boost##YAXXZ) C:\Visual Studio 2012 Projects\MMS_Solution\MMS_Prj_FindFile\MMS_Prj_FindFile.obj MMS_Prj_FindFile
[...]
Error 5 error LNK2019: unresolved external symbol "public: class boost::filesystem::path __cdecl boost::filesystem::path::root_path(void)const " (?root_path#path#filesystem#boost##QEBA?AV123#XZ) referenced in function main C:\Visual Studio 2012 Projects\MMS_Solution\MMS_Prj_FindFile\MMS_Prj_FindFile.obj MMS_Prj_FindFile
Error 6 error LNK2019: unresolved external symbol "public: class boost::filesystem::path __cdecl boost::filesystem::path::root_name(void)const " (?root_name#path#filesystem#boost##QEBA?AV123#XZ) referenced in function main C:\Visual Studio 2012 Projects\MMS_Solution\MMS_Prj_FindFile\MMS_Prj_FindFile.obj MMS_Prj_FindFile
[...]
Error 18 error LNK1120: 17 unresolved externals C:\Visual Studio 2012 Projects\MMS_Solution\x64\Debug\MMS_Prj_FindFile.exe MMS_Prj_FindFile
Here's the linker options (if others are needed I can add them):
Linker -> General
Enabled Incremental Linking = Yes (/INCREMENTAL)
Ignore Import LIbrary = No
Register Output = No
Per-user Redirection = No
Additional Library Directories = C:\openssl\lib;C:\boost\lib
Link Library Dependencies = Yes
Use Library Dependency Inputs = No
Prevent Dll Binding =
Linker -> Input
All of these are blank except for
Additional Dependencies = ssleay32.lib;libeay32.lib;Ws2_32.lib;libboost_system-vc110-mt-1_54.lib;libboost_filesystem-vc110-mt-1_54.lib;%(AdditionalDependencies)
Here's the code:
//Boost Includes
#include <boost/filesystem.hpp>
//Boost linking because visual studio won't link it (ugh)
#pragma comment (lib, "libboost_system-vc110-mt-gd-1_54.lib")
#pragma comment (lib, "libboost_filesystem-vc110-mt-gd-1_54.lib")
//Normal Includes
#include <iostream>
#include <string>
namespace bfs = boost::filesystem;
int main(int argc, char* argv[])
{
std::vector<std::string> foundPaths;
bfs::directory_iterator eit;
for(bfs::directory_iterator it("."); it != eit; it++)
{
if(!bfs::is_regular_file(it->status()))
continue;
bfs::path foundPath = it->path();
foundPaths.push_back("Root name: " + foundPath.root_name().string() + "\n" +
"Root dir : " + foundPath.root_directory().string() + "\n" +
"Root path: " + foundPath.root_path().string() + "\n" +
"Rel path: " + foundPath.relative_path().string() + "\n" +
"Prnt path: " + foundPath.parent_path().string() + "\n" +
"File name: " + foundPath.filename().string() + "\n" +
"Stem : " + foundPath.stem().string() + "\n" +
"Extension: " + foundPath.extension().string() + "\n");
}
for(std::vector<std::string>::iterator it = foundPaths.begin(); it != foundPaths.end(); ++it)
{
std::cout << *it << std::endl;
}
return 0;
}
When building Boost, make sure that you're using the parameter "address-model=64" if you're building for 64 bit. It says in the documentation that your compiler should choose the right one if it is configured correctly but apparently mine was not and was building 32 bit binaries when I wanted 64 bit binaries.

C++ Connector to MySQL

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