This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Problems importing libraries to my c++ project, how to fix this?
(2 answers)
Closed 4 years ago.
I am working with OpenSSL to try and get the SHA512 Hash function to work. When I am writing the code, Visual Studio's intellisense finds the function SHA512as well as all of the parameters that are included with it, but when I go to build the project, I get the error, "unresolved external symbol SHA512 referenced in function main." Here is what I have so far, it's based on a small example here.
stdafx.h
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
#define _AFX_NO_MFC_CONTROLS_IN_DIALOGS // remove support for MFC controls in dialogs
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#endif
#include <afx.h>
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <iostream>
// TODO: reference additional headers your program requires here
#include <openssl/sha.h>
test.cpp
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
int main() {
unsigned char digest[SHA512_DIGEST_LENGTH];
char string[] = "hello world";
SHA512((unsigned char*)&string, strlen(string), (unsigned char*)&digest);
char mdString[SHA512_DIGEST_LENGTH * 2 + 1];
for (int i = 0; i < SHA512_DIGEST_LENGTH; i++)
sprintf(&mdString[i * 2], "%02x", (unsigned int)digest[i]);
printf("SHA512 digest: %s\n", mdString);
return 0;
}
I have even checked and confirmed that SHA512 is in the sha.h file that is included in the stdafx.h file as well.
Related
I downloaded OpenCV 3.0.0-rc1 and build it using CMAKE-gui 3.2.2 using VS2012 Win64 compiler. Binaries and libraries got generated and I set it up with Qt 64 bit. All programs are working fine except when I try to use the feature cv::LineSegmentDetector it shows a compile error in private.hpp file. The error says
unexpected end-of-line
My code is as follows
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/private.hpp>
#include <opencv2/core/utility.hpp>
using namespace std;
int main()
{
cv::Mat image = cv::imread("C:\\Users\\IMAGE\\Desktop\\PROJ\\SAMPLE.png");
cv::imshow("TEST",image);
cv::waitKey();
cv::LineSegmentDetector lsd;
return 0;
}
And on following the error I found the 2nd line of the following part of the code in private.hpp as error highlighted.
#ifdef HAVE_EIGEN
# if defined __GNUC__ && defined __APPLE__
# pragma GCC diagnostic ignored "-Wshadow"
# endif
# include <Eigen/Core>
# include "opencv2/core/eigen.hpp"
#endif
# if defined __GNUC__ && defined __APPLE__
Please let me know if I am doing some implementation mistake or some changes in the private.hpp can fix this error. I am using windows 8 64 bit.
oh, never try to use something, that is called "private", i guess...
#include <opencv2/opencv.hpp> // includes all others
#include <opencv2/core/utility.hpp> // getTickCount, etc.
int main()
{
// LineSegmentDetector is an abstract class, you can't create an
// instance on the stack, but need to use Ptr and factory:
cv::Ptr<cv::LineSegmentDetector> lsd = cv::createLineSegmentDetector();
return 0;
}
I tried to make console application that is using my DLL that is taking care of Kinect.
When I am building my project I get:
2>e:\projects\c++\vs\kinect dll\consoleapplication1\consoleapplication1.cpp(4):
warning C4627: '#include "KinectDLL.h"': skipped when looking for precompiled header use
2> Add directive to 'stdafx.h' or rebuild precompiled header
2> e:\michał\projects\c++\vs\kinect dll\kinect dll\depthreader.h(4):
fatal error C1083: Cannot open include file: 'NuiApi.h': No such file or directory
Note: ConsolApplication1 and Kinect DLL are 2 projects in the same solution, first one have one dependency – Kinect DLL project as DLL. I have “use precompile headers” turned off in both projects!
Kinect DLL projects:
KinectDLL.h:
#ifdef KINECTDLL_EXPORTS
#define KINECTDLL_API __declspec(dllexport)
#else
#define KINECTDLL_API __declspec(dllimport)
#endif
DepthReader.h:
#pragma once
#include <ole2.h>
#include <Windows.h>
#include "NuiApi.h"
#include "KinectDLL.h"
namespace KinectDLL{
class DepthReader{
static KINECTDLL_API const int depthWidth = 640;
static KINECTDLL_API const int depthHeight = 480;
static KINECTDLL_API const int bytesPerPixel = 4;
public:
KINECTDLL_API DepthReader(void);
KINECTDLL_API ~DepthReader(void);
KINECTDLL_API int Run(HINSTANCE hInstance, int nCmdShow);
private:
HANDLE depthStreamHandle;
HANDLE nextDepthFrameEvent;
HANDLE depthStream;
BYTE* depthRGBX;
bool nearMode;
INuiSensor* sensor;
//HWND m_hWnd;
HRESULT CreateFirstConnected();
void Update();
void ProcessDepth();
};
}
DepthReader.cpp
#include "stdafx.h"
#include "DepthReader.h"
namespace KinectDLL{
DepthReader::DepthReader(void) :
nextDepthFrameEvent(INVALID_HANDLE_VALUE),
depthStreamHandle(INVALID_HANDLE_VALUE),
nearMode(false),
sensor(NULL)
{
// create heap storage for depth pixel data in RGBX format
depthRGBX = new BYTE[depthWidth*depthHeight*bytesPerPixel];
}
… and so on, mostly copy and pase from MS Kinect examples...
Consoleapplication1 project:
Consolapplication1.cpp:
#include "KinectDLL.h"
#include "stdafx.h"
#include "Rotations.h"
#include "Camera.h"
#include "FileLoader.h"
#include "DepthReader.h"
using namespace std;
Camera camera;
Rotations rotations;
FileLoader fileLoader;
KinectDLL::DepthReader depthReader;
… then there is OpenGL, points from file. I am using Kinect to contole the scene, not to display data from it. No depthReader for now.
Clearly I am doing something stupid but I can't see what. I am reading Microsoft examples about DLL in VC++ but I can't see what is wrong.
I have just finished created a dll with some functions that depend on the skeleton stream from the kinect. What I did was something like this:
#ifdef KINECTFUNCTIONSDLL_EXPORTS
#define KINECTFUNCTIONSDLL_API __declspec(dllexport)
#else
#define KINECTFUNCTIONSDLL_API __declspec(dllimport)
#endif
#include <Windows.h>
#include <NuiApi.h>
using namespace std;
#include <string>
namespace KinectFunctions{
class GestureRecognizer
{
public:
Vector4 KINECTFUNCTIONSDLL_API resta(Vector4 vector1,Vector4 vector2);
}
}
and now for the .cpp:
#include "KinectFunctionsDLL.h"
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <fstream>
using namespace std;
namespace KinectFunctions{
Vector4 GestureRecognizer::resta(Vector4 vector1,Vector4 vector2){
Vector4 salida;
salida.x=vector1.x-vector2.x;
salida.y=vector1.y-vector2.y;
salida.z=vector1.z-vector2.z;
return salida;
}
}
Keep in mind that the project you use to create the dll must be created checking the DLL option (it's a checkbox that appears when you choose to create a new project. Like it is shown here:
https://www.youtube.com/watch?v=yEqRyQhhto8
And of course you need to add the dependencies for the kinect dll, the kinect10.lib and the headers, like in any project where you want to use the device.
Am trying to include CString in my cpp file but am getting this error if i include afxinet.h
"windows.h already included afxv_w32.h"
These are my header files :
#include stdafx.h
#include shlwapi.h
#include Tlhelp32.h
#include hooks.h
#include stdio.h
#include common1.h
#include SafeLogger.h
#include io.h
#include tinyxml.h
#include winsock.h>
#pragma comment(lib, "Ws2_32.lib")
#include afxinet.h
I havent included the gaurds in stack to display here.
how to solve this issue and get to include CString in my file
Why are you adding afxinet.h if you want CString?
You should include atlstr.h to get CString - particularly if your project isn't MFC based.
Use /showIncludes option in C++ settings (Under Advanced). This will show how headers are being included (in tree-format). As another suggestion, you should include only files that are needed.
By including < afx.h >, you should be able to use CString class in cpp file.
#include <afx.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
CString str("Santosh");
wcout << LPCTSTR(str) << endl;
return 0;
}
Additionally, you will need to define _AFXDLL preprocessor
I'm currently using the triangle library in my program. The library contains only .c and .h files (no .lib). I get the following error on Visual Studio C++ 2010:
1>data.obj : error LNK2019: unresolved external symbol _triangulate referenced in function "struct triangulateio __cdecl readfile(void)" (?readfile##YA?AUtriangulateio##XZ)
The header file of my data.cpp is the following:
#ifndef DATA_H
#define DATA_H
#include <WinSock2.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <string>
#include <time.h>
#include <GL/gl.h> //include the gl header file
#include <GL/glut.h> //include the glut header file
#include <GL/glu.h> //include the glut header file
#include <armadillo>
//Namespace
using namespace std;
using namespace arma;
extern "C"
{
#ifdef SINGLE
#define REAL float
#else /* not SINGLE */
#define REAL double
#endif /* not SINGLE */
#include "triangle.h"
}
triangulateio readfile();
#endif
Data.cpp
triangulate("pczAevn", &in, &mid, &vorout);
I've already made my program work with a Makefile of mine on Ubuntu, but I need to run my program on windows.
Feel free to ask for more information.
EDIT #1:
If you use the triangle library with VS, you have to put the following instruction on top of the triangle.c file #define TRILIBRARY
Now it compile. Thank you very much for the help.
The linker can't find a definition for "triangulateio readfile()", if it's defined in the .c file my guess is that it isn't built. If you include it in the project it could work.
I am trying to implement a test project using the Point Cloud Library and OpenCV with multiple files. When I try to compile, I get the "already defined error" message. Probably I'm doing something stupid that cannot realize for some reason - I tried out a couple of solutions found here, none of them seemed to be help in my case.
What I have:
A libs.h file, where I load the lib files (in Project properties, I only set up the .lib paths and load the libs "by hand", like the headers):
#pragma once
#ifndef PCLTEST_LIBS
#define PCLTEST_LIBS
#ifdef _DEBUG
#pragma comment(lib, "pcl_apps-gd.lib")
#pragma comment(lib, "pcl_common-gd.lib")
// a bunch of other debug libs
#else
// the release libs
#endif
#endif
A main file from which I basically deleted everything at this point to debug:
// load the libs
#ifndef PCLTEST_LIBS
#include "libs.h"
#endif
// pcltest includes
// if only this first one is #included, everything is OK
#include "opencvOperations.h"
// #including this one causes the error
#include "files.h"
// these ones are not working also
//#include "cloudOperations.h"
//#include "visualize.h"
// c++ headers
#include <stdio.h>
#include <string>
//#include <sstream>
//#include <iostream>
void writeInfo()
{
// some std::cout calls
}
int main( int argc, char* argv[] )
{
writeInfo();
// this function is in opencvOperations.h and works OK
pcltest::openLena();
}
Then I get several error messages in my main.obj that some (PCL related) symbols are already defined in files.obj. I use PCL related calls both in opencvOperations and files, the first one is OK, the second one does not work.
Edit:
To add more detail, my files.h header:
#pragma once
#ifndef PCLTEST_FILES
#define PCLTEST_FILES
// pcl headers
#ifndef PCL_COMMON_H_
#include <pcl/common/common_headers.h>
#endif
#ifndef PCL_IO_FILE_IO_H_
#include <pcl/io/file_io.h>
#endif
#ifndef PCL_IO_PCD_IO_H_
#include <pcl/io/pcd_io.h>
#endif
#ifndef PCL_IO_PLY_IO_H_
#include <pcl/io/ply_io.h>
#endif
// boost headers
#ifndef BOOST_FILESYSTEM_OPERATIONSX_HPP
#include <boost/filesystem/operations.hpp>
#endif
#endif
namespace pcltest
{
// function to open PCL or binary PLY files
pcl::PointCloud<pcl::PointXYZ>::Ptr openCloud(std::string filename);
// function to save the point cloud to PCD format
void saveCloud();
}
Before splitting the code into separate files, everything worked well (with the same project settings).
Edit2:
I located the source of the problem,
#include <pcl/io/ply_io.h>
causes this. For now, I got rid of everything related to PLY and everything works fine. I'll look at it later, this might be a PCL library specific issue. Still strange to me why this call causes linker error in an other file, where I don't even use PLY related functions/variables.
I had the same problem as you had. I had a surface.h and surface.cpp file, and I found out that I had to include the ply_io.h file from surface.cpp rather than surface.h and now it compiles fine. I hope that helps or makes sense! haha
If a constant is being instantiated in an include one can also use selectany, per http://msdn.microsoft.com/en-us/library/5tkz6s71%28v=vs.80%29.aspx -- in my case:
const int CSdata[] = {1, 2, 3, 4};
when included in more than one source part produces LNK2005 at link time, avoided via:
const __declspec(selectany) int CSdata[] = {1, 2, 3, 4};
Non-portable, yeah ...