I'm trying to load a pcd file using pcl library, I do and show it using cloud viewer but I'm trying to use PCLVisualizer.
When I use addPointCloud function I have an error:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: static class vtkMatrix4x4 * __cdecl vtkMatrix4x4::New(void)" (?New#vtkMatrix4x4##SAPEAV1#XZ) referenced in function "public: static class vtkSmartPointer __cdecl vtkSmartPointer::New(void)" (?New#?$vtkSmartPointer#VvtkMatrix4x4####SA?AV1#XZ) SamplePCL C:\Users\Nima_S_H\Documents\Visual Studio 2015\Projects\SamplePCL\SamplePCL\Source.obj 1
My codes:
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_WARNINGS
#define _HAS_ITERATOR_DEBUGGING 0
#define _ITERATOR_DEBUG_LEVEL 0
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
void main()
{
typedef pcl::PointXYZRGB PTYPE;
pcl::PointCloud<PTYPE>::Ptr myCloudPtr(new pcl::PointCloud<PTYPE>);
if (pcl::io::loadPCDFile("e:/myCloudASCII.pcd", *myCloudPtr) == -1)
{
PCL_ERROR("Could not read PCD file.");
return;
}
pcl::visualization::PCLVisualizer viz;
viz.addPointCloud(myCloudPtr);
viz.spin();
}
this works for me.
Edit: actually it works even without the spinOnce . just use spin..
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_WARNINGS
#define _HAS_ITERATOR_DEBUGGING 0
#define _ITERATOR_DEBUG_LEVEL 0
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
int main()
{
typedef pcl::PointXYZ PTYPE;
pcl::PointCloud<PTYPE>::Ptr myCloudPtr(new pcl::PointCloud<PTYPE>);
if (pcl::io::loadPCDFile("test.pcd", *myCloudPtr) == -1)
{
PCL_ERROR("Could not read PCD file.");
return 0;
}
pcl::visualization::PCLVisualizer viz;
viz.addPointCloud(myCloudPtr);
while (!viz.wasStopped ())
{
viz.spinOnce (100);
}
return 1;
}
Related
I'm trying to use bit7z in my C++ code to create a program that zips a directory. I'm receiving a LNK2019 error for something called _imp_CharUpperW#4 in my bit7z_d.lib. My IDE is Visual Studio Community 2019 and I use C++ 20.
These are my files:
main.cpp
#include <QCoreApplication>
#include <string>
#include <iostream>
#include <filesystem>
#include <bit7z.hpp>
#include "main.h"
#include <bitcompressor.hpp>
namespace fs = std::filesystem;
using namespace bit7z;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::string path = "C:/Users/aretz/Downloads/test";
for (const auto& entry : fs::directory_iterator(path))
std::cout << entry.path() << std::endl;
return a.exec();
}
void AIXLogger::CompressDir() {
Bit7zLibrary lib{ L"C:/Program Files/7-Zip/7z.dll" };
BitCompressor compressor{ lib, BitFormat::Zip };
vector< wstring > files = { L"C:/Users/aretz/Downloads/test" };
wstring zip = { L"output_archive.zip" };
compressor.compressFiles( files , zip );
}
void AIXLogger::Execute() {
CompressDir();
}
main.h
#pragma once
#include <qwidget.h>
#include <qobject.h>
#include <bit7z.hpp>
class AIXLogger : public QWidget
{
Q_OBJECT
public slots:
public:
void CompressDir();
void Execute();
};
aixLogger.pro
# ----------------------------------------------------
# This file is generated by the Qt Visual Studio Tools.
# ------------------------------------------------------
TEMPLATE = app
TARGET = aixLogger
DESTDIR = ./Debug
CONFIG += debug console
DEPENDPATH += .
MOC_DIR += .
OBJECTS_DIR += debug
UI_DIR += GeneratedFiles
RCC_DIR += GeneratedFiles
include(aixLogger.pri)
Screenshots of my Properties are here:
Additional Include Directories
Additional Library Directories
Additional Dependencies
This is the exact error:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol __imp__CharUpperW#4 referenced in function "wchar_t __cdecl MyCharUpper(wchar_t)" (?MyCharUpper##YA_W_W#Z) aixLogger D:\local\aretz\Programmierung\git-workplace\aixLogger\bit7z_d.lib(MyString.obj) 1
I'm desperately trying to make a dll with CUDA functions but I can't make it work.
I tried the method explained here :Creating DLL from CUDA using nvcc
to compile but I've got the following errors :
nvcc :
warning: __declspec attributes ignored
At line:1 char:1
+ nvcc -o ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (...ributes ignored:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
...\kernel.cu(81): warning: __declspec attributes ignored
...\cudaFFT.h(21): warning: __declspec attributes ignored
.../kernel.cu(81): warning: __declspec attributes ignored
nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
kernel.cu
CrÚation de la bibliothÞque C:/Users/alombet/Documents/Visual Studio 2015/Projects/Test/kernel.lib et de l'objet C:/Users/alombet/Documents/Visual Studio 2015/Projects/Test/kernel.exp
tmpxft_00003b9c_00000000-30_kernel.obj : error LNK2019: symbole externe non rÚsolu cufftPlan1d rÚfÚrencÚ dans la fonction AllocateMemoryForFFTs
tmpxft_00003b9c_00000000-30_kernel.obj : error LNK2019: symbole externe non rÚsolu cufftExecD2Z rÚfÚrencÚ dans la fonction ComputeFFT
tmpxft_00003b9c_00000000-30_kernel.obj : error LNK2019: symbole externe non rÚsolu cufftDestroy rÚfÚrencÚ dans la fonction DeAllocateMemoryForFFTs
C:/Users/alombet/Documents/Visual Studio 2015/Projects/Test/kernel.dll : fatal error LNK1120: 3 externes non rÚsolus
First of all the __declspec seems to be ignored, and after that it seems the compiler doesn't find the functions I use in the cuda libraries. I'm really not accustomed to compiling by hand. Usually, I rely on the IDE to do it and thus I am completely lost here.
Here is the code :
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include <iostream>
// includes, system
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
// includes, project
#include <cuda_runtime.h>
#include <cufft.h>
#include <cufftXt.h>
#define LIBRARY_EXPORTS 1
#ifdef LIBRARY_EXPORTS
#define LIBRARY_API __declspec(dllexport)
#else
#define LIBRARY_API __declspec(dllimport)
#endif
#include "cudaFFT.h"
#ifdef __cplusplus
extern "C" {
#endif
int LIBRARY_API __cdecl numberOfGpus()
{
int nDevices;
cudaGetDeviceCount(&nDevices);
return nDevices;
}
cufftDoubleReal *host_input;
cufftDoubleReal *device_input;
cufftDoubleComplex *host_output;
cufftDoubleComplex *device_output;
cufftHandle plan;
cudaError LIBRARY_API __cdecl AllocateMemoryForFFTs(int maxSize, int maxBatch)
{
int width = maxSize; int height = maxBatch;
cudaError err = cudaMallocHost((void **)&host_input, sizeof(cufftDoubleReal) * width * height);
if (err)
return err;
err = cudaMallocHost((void **)&host_output, sizeof(cufftDoubleComplex) * (width / 2 + 1) * height);
if (err)
return err;
err = cudaMalloc((void **)&device_input, sizeof(cufftDoubleReal) * width * height);
if (err)
return err;
err = cudaMalloc((void **)&device_output, sizeof(cufftDoubleComplex) * (width / 2 + 1) * height);
if (err)
return err;
cufftResult res = cufftPlan1d(&plan, width, CUFFT_D2Z, height);
if (res)
return (cudaError)res;
return cudaSuccess;
}
double* LIBRARY_API __cdecl GetInputDataPointer()
{
return host_input;
}
cudaError LIBRARY_API __cdecl ComputeFFT(int size, int batch, double2** result)
{
cudaError err = cudaMemcpy(device_input, host_input, sizeof(cufftDoubleReal) * size * batch, cudaMemcpyHostToDevice);
if (err)
return err;
cufftResult res = cufftExecD2Z(plan, device_input, device_output);
if (res)
return (cudaError)res;
err = cudaMemcpy(host_output, device_output, sizeof(cufftDoubleComplex) * (size / 2 + 1) * batch, cudaMemcpyDeviceToHost);
if (err)
return err;
*result = host_output;
return cudaSuccess;
}
void LIBRARY_API __cdecl DeAllocateMemoryForFFTs()
{
cufftDestroy(plan);
cudaFree(device_input);
cudaFree(device_output);
cudaFreeHost(host_input);
cudaFreeHost(host_output);
}
#ifdef __cplusplus
}
#endif
Ok I found my problems, I leave the solution here in case it can help someone.
I removed the LIBRARY_API keyword from the .cu
In the .h I moved the LIBRARY_API at the very beginning of each declaration.
I changed the project properties in vs to generate a dll.
Let VS compile
I am trying to run the following code to read the max processor throttle:
#include <iostream>
#include <string>
#include <tchar.h>
#include <windows.h>
#include <Powerbase.h>
#include <PowrProf.h>
using namespace std;
int main()
{
SYSTEM_POWER_CAPABILITIES sysc;
while (GetPwrCapabilities(&sysc)) {
cout << " Your Max Throttle is: " << static_cast<double> (sysc.ProcessorMaxThrottle) << endl;
}
Sleep(10000);
return 0;
}
However , I am receiving the following error:
...error LNK2019: unresolved external symbol _GetPwrCapabilities#4 referenced in function _main
...fatal error LNK1120: 1 unresolved externals
I tried the solution related to make sure the linker set to console program but it does not work. Any suggestion ?
I am using MSVS 2013.
Thanks
To make it work, you need to add PowrProf.lib to your project setting:
Project Properties -> Linker -> Input -> Additional Dependencies
I am working on an Ogre project and I am getting some issues with Xcode.
Whenever I make the scene manager pointer static, the program does not compile and I get the following error:
Undefined symbols for architecture x86_64:
"OgreInit::sceneManager", referenced from:
OgreInit::initOgre() in OgreInit.o
OgreInit::initScene() in OgreInit.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here is my OgreInit.cpp
#include <iostream>
#include <exception>
#include <string>
#include "OGRE/Ogre.h"
#include "OGRE/OgreException.h"
#include "OGRE/OgreRoot.h"
#include "OGRE/OgreResourceManager.h"
#include "OGRE/OgreMath.h"
#include "MainLoop.h"
#include "WorkingDirectory.h"
#include "OgreInit.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
#include "macUtils.h"
#endif
OgreInit::OgreInit()
{
mainLoop = new MainLoop();
mainLoop->startLoop();
initOgre();
initScene();
}
void OgreInit::initOgre()
{
root = new Ogre::Root(WorkingDirectory::getResourcesDirectory() + "plugins.cfg", WorkingDirectory::getResourcesDirectory() + "window.cfg", "");
root->showConfigDialog();
window = root->initialise(true);
sceneManager = root->createSceneManager(Ogre::ST_GENERIC);
camera = sceneManager->createCamera("mainCamera");
camera->setNearClipDistance(0.1);
camera->setFarClipDistance(300);
camera->setPosition(0, 0, 80);
//camera->lookAt(Ogre::Vector3::ZERO);
cameraNode = sceneManager->getRootSceneNode()->createChildSceneNode();
cameraNode->attachObject(camera);
viewport = window->addViewport(camera);
viewport->setClearEveryFrame(true);
viewport->setAutoUpdated(true);
viewport->setBackgroundColour(Ogre::ColourValue(1, 0, 1));
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(WorkingDirectory::getModelDirectory(), "FileSystem");
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}
void OgreInit::initScene()
{
sceneManager->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f));
Ogre::Entity *ogreHead = sceneManager->createEntity("Head", "ogrehead.mesh");
Ogre::SceneNode *headNode = sceneManager->getRootSceneNode()->createChildSceneNode("HeadNode");
headNode->attachObject(ogreHead);
headNode->rotate(*new Ogre::Vector3(0, 1, 0), (Ogre::Radian)Ogre::Math::DegreesToRadians(90));
Ogre::Light *light = sceneManager->createLight("MainLight");
light->setPosition(20.0f, 80.0f, 50.0f);
}
//init resources before scene :! and translate before attaching
OgreInit::~OgreInit()
{
}
And of course the header:
#ifndef __OgreTest__OgreInit__
#define __OgreTest__OgreInit__
#include <iostream>
#include <string>
#include <memory>
#include "OGRE/Ogre.h"
#include "MainLoop.h"
class OgreInit
{
public:
OgreInit();
~OgreInit();
private:
void initOgre();
void initScene();
MainLoop *mainLoop;
Ogre::Root *root;
Ogre::RenderWindow *window;
static Ogre::SceneManager *sceneManager;
Ogre::Viewport *viewport;
Ogre::Camera *camera;
Ogre::SceneNode *cameraNode;
};
#endif /* defined(__OgreTest__OgreInit__) */
I have seen this issue on Stackoverflow quite often, but usually it happened because some required libraries were not included. I don't think that is the issue here because I am not getting any errors if I change: static Ogre::SceneManager *sceneManager; to: Ogre::SceneManager *sceneManager;
Thanks in advance.
As well as declaring it in your header file, you need to actually define the sceneManager in your implementation file:
...
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
#include "macUtils.h"
#endif
Ogre::SceneManager *OgreInit::sceneManager = 0;
OgreInit::OgreInit()
{
...
I have tried writing a simple program to get information from a website. I can't compile as I get the LNK2019 error for InternetReadFile, InternetOpenUrl, etc. and e.g.
1>GetInternetInfo.obj : error LNK2019: unresolved external symbol _imp_InternetReadFile#16 referenced in function _main
I assume that means I did not define these functions, that I did not include the correct library. I thought including #include would fix it, but it does not seem to help. I am running this on Visual Studio 2010 using C++. Below is my program. Any help is appreciated.
#include <string>
#include <iostream>
#include <fstream>
#include <windows.h>
#include <wininet.h>
#include <winsock.h>
#include <stdio.h>
#include <stdarg.h>
using namespace std;
int main()
{
HINTERNET hOpen, hURL;
LPCWSTR NameProgram = L"Webreader"; // LPCWSTR == Long Pointer to Const Wide String
LPCWSTR Website;
char file[101];
unsigned long read;
//Always need to establish the internet connection with this funcion.
if ( !(hOpen = InternetOpen(NameProgram, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 )))
{
cerr << "Error in opening internet" << endl;
return 0;
}
Website = L"http://www.google.com";
hURL = InternetOpenUrl( hOpen, Website, NULL, 0, 0, 0 ); //Need to open the URL
InternetReadFile(hURL, file, 100, &read);
while (read == 100)
{
InternetReadFile(hURL, file, 100, &read);
file[read] = '\0';
cout << file;
}
cout << endl;
InternetCloseHandle(hURL);
return 0;
}
Please include "Wininet.lib" in your project settings.
Project->Properties->Configuration Properties->Linker->Input->Additional Dependencies
You can also add this line to your code after include section instead of adding library to the properties:
#pragma comment(lib, "wininet.lib")
Did you link to wininet.lib?
http://msdn.microsoft.com/en-us/library/aa385103(VS.85).aspx