I have a small piece of code, which gives this error when trying to make, here is the CMakelists.txt being used:
cmake_minimum_required(VERSION 2.8) #Specify the minimum CM$
project(gaussian) $
find_package(CUDA REQUIRED) #find the CUDA $
find_package(ITK REQUIRED)
include( ${ITK_USE_FILE} )
#message("Debug: ITK ${ITK_DIR}")
include_directories(${CUDA_INCLUDE_DIRS}) #Specify the CUDA include direc$
add_executable(gaussian source/main.cu) #create an executabl$
#specify any additional libraries here (CUFFT and CUBLAS can be useful)
target_link_libraries(gaussian ${CUDA_cufft_LIBRARY} ${CUDA_cublas_LIBRARY} ${I$
The main.cu file is below:
#include <fstream>
#include <cuda.h>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <ctime>
#include <cuda_runtime_api.h>
#include <cufft.h>
#include "itkImage.h"
using namespace std;
static void HandleError( cudaError_t err, const char *file, int line )
{
if (err != cudaSuccess)
cout<<cudaGetErrorString(err)<<" in "<< file <<" at line "<< line<<endl;
}
#define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))
int main(int argc, char* argv[])
{
typedef itk::Image< unsigned short, 3 > ImageType;
ImageType::Pointer image = ImageType::New();
cout << "ITK Hello World !" << endl;
int nDevices;
cout<<"DEVICE SPECIFICATIONS: "<<endl<<endl;
HANDLE_ERROR(cudaGetDeviceCount(&nDevices));
return 0;
}
While building, the linkers are set. I am unable to figure out what is wrong here.
I found the issue here, firstly as pointed I needed to use cuda_add_executable, instead of add_executable. Doing that and building, I get errors like:
overriding itk::ImageBase<VImageDimension>::Pointer
itk::ImageBase<VImageDimension>::CreateAnother() const [with unsigned int VImageDimension = 3u, itk::ImageBase<VImageDimension>::Pointer = itk::SmartPointer<itk::ImageBase<3u> >]
These are because the CUDA compiler has trouble with the C++ features used b y ITK. Using the ITK features in a .cxx file and calling CUDA functions in .cu file helped.
Credits: http://public.kitware.com/pipermail/insight-developers/2012-October/022116.html
Related
I'm having problems using std::vector<int> in C++ on Mac OSX Catalina. I have a function static int insertMoneyData(std::vector<int> money) that writes data to an SQLite database. The function is declared in SQLFunctions.h and defined in SQLFunctions.cc.
When also running the function from SQLFunctions.cc, everything works fine in the compilation (using c++ in make). But when I try to run the same function from another file (city.cc), I get the following error:
Undefined symbols for architecture x86_64:
"insertMoneyData(std::__1::vector<int, std::__1::allocator<int> >)", referenced from:
City::save_money_data() in city.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1
(use -v to see invocation)
make: *** [main] Error 1
Calling insertMoneyData(money_data) from SQLFunctions.cc, where it is defined, works fine.
//SQLFunctions.cc
#include <iostream>
#include <sqlite3.h>
#include <stdio.h>
#include <vector>
#include <cstring>
#include "SQLfunctions.h"
using namespace std;
using Record = std::vector<std::string>;
using Records = std::vector<Record>;
int initiateDB() {
std::vector<int> money_data;
money_data.push_back(1);
money_data.push_back(2);
money_data.push_back(3);
money_data.push_back(4);
money_data.push_back(5);
money_data.push_back(6);
money_data.push_back(7);
money_data.push_back(8);
money_data.push_back(9);
money_data.push_back(10);
money_data.push_back(11);
money_data.push_back(12);
money_data.push_back(13);
insertMoneyData(money_data);
}
static int insertMoneyData(std::vector<int> money) {
const char* dir = "/Users/bennyjohansson/Projects/ekosim/myDB/ekosimDB.db";
sqlite3* DB;
char* messageerror;
int exit = sqlite3_open(dir, &DB);
string sql = "INSERT INTO MONEY_DATA (TIME, BANK_CAPITAL, BANK_LOANS, BANK_DEPOSITS, BANK_LIQUIDITY, CONSUMER_CAPITAL, CONSUMER_DEPOSITS, CONSUMER_DEBTS, COMPANY_DEBTS, COMPANY_CAPITAL, MARKET_CAPITAL, CITY_CAPITAL, TOTAL_CAPITAL) VALUES(";
sql.append(std::to_string(money[0]) + ", ");
sql.append(std::to_string(money[1]) + ", ");
sql.append(std::to_string(money[2]) + ", ");
sql.append(std::to_string(money[3]) + ", ");
sql.append(std::to_string(money[4]) + ", ");
sql.append(std::to_string(money[5]) + ", ");
sql.append(std::to_string(money[6]) + ", ");
sql.append(std::to_string(money[7]) + ", ");
sql.append(std::to_string(money[8]) + ", ");
sql.append(std::to_string(money[9]) + ", ");
sql.append(std::to_string(money[10]) + ", ");
sql.append(std::to_string(money[11]) + ", ");
sql.append(std::to_string(money[12]) + ");");
exit = sqlite3_exec(DB, sql.c_str(), NULL, 0, &messageerror);
}
However, when I call the function from another file, it doesn't work:
//City.cc
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <list>
#include <fstream>
#include <cmath>
#include <random>
#include "SQLfunctions.h"
using namespace std;
void City::save_money_data() {
std::vector<int> money_data;
money_data.push_back(1);
money_data.push_back(2);
money_data.push_back(3);
money_data.push_back(4);
money_data.push_back(5);
money_data.push_back(6);
money_data.push_back(7);
money_data.push_back(8);
money_data.push_back(9);
money_data.push_back(10);
money_data.push_back(11);
money_data.push_back(12);
money_data.push_back(13);
insertMoneyData(money_data);
}
Declaring:
//SQLFunctions.h
#ifndef SQL_FUNCTIONS_H
#define SQL_FUNCTIONS_H
#include <iostream>
#include <sqlite3.h>
#include <stdio.h>
using namespace std;
using Record = std::vector<std::string>;
using Records = std::vector<Record>;
int initiateDB();
static int createDB(const char* s);
static int createParameterTable(const char* s);
static int createDataTable(const char* s);
static int createMoneyTable(const char* s);
static int insertParameterData(const char* s);
static int insertMoneyData(std::vector<int> money); //
static int updateData(const char* s);
static int updateParameter(const char* s, string, double);
static int deleteTheData(const char* s);
static int selectData(const char* s);
static int callback(void* NotUsed, int argc, char** argv, char** azColName);
int select_callback(void *p_data, int num_fields, char **p_fields, char **p_col_names);
Records select_stmt(const char* stmt, const char* s);
#endif
Problem is obsolete keyword static before each function.
static keyword has multiple meanings. In this context it means: this function definition should be visible only in this translation unit (translation unit means sources compiled during single compilation - so source file with all its includes).
So you defined a function which should be accessed by other translation units (other sources), but you have limited its visibility to single file where it is defined. That is why linker complains that can't find this functions.
I am new to llvm , writing the program "main.cpp" of https://github.com/davidar/lljvm/blob/master/backend/main.cpp.
I stuck at the error while executing the command : "pm.run(m)"
error: no matching function for call to ‘llvm::legacy::PassManager::run(llvm::Expected<std::unique_ptr<llvm::Module> >&)
Here is my source code:
#include "backened.h"
#include <iostream>
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/PassManager.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/IR/DataLayout.h"
#include <llvm/Transforms/Scalar.h>
#include "llvm/IR/LegacyPassManager.h"
using namespace llvm;
using namespace std;
static cl::opt<string> input(cl::Positional, cl::desc("Bitcode File.."),cl::Required);
static cl::opt<string> classname("classname",cl::desc("Binary name of the generated class..."));
int main(int argc, char** argv)
{
cl::ParseCommandLineOptions(argc, argv, "Hi..");
LLVMContext context;
ErrorOr<unique_ptr<MemoryBuffer>> mb = MemoryBuffer::getFile(input);
if(error_code ec = mb.getError()) {
errs() << ec.message();
return 1;
}
Expected<unique_ptr<Module>> m = parseBitcodeFile(mb->get()->getMemBufferRef(),context);
if(error_code ec= errorToErrorCode(m.takeError()) )
{
errs() <<"Unable to read bitcode file.." <<ec.message() ;
}
PassManager<Module> pm;
pm.add(createVerifierPass());
pm.add(createGCLoweringPass());
pm.add(createLowerSwitchPass());
pm.add(createCFGSimplificationPass());
pm.add(new JVMWriter(fouts(), classname, debugLevel));
pm.add(createGCInfoDeleter());
pm.run(*m);
return 0;
}
Please help me.
I am using Visual Studio 2010, with OpenCV 3.0. I'm trying to load some images from a folder but I am having problems.
Firstly I did not have the file dirent.h, so I downloaded it in order to get the DIR* and "dirent*" structures to access to the files. All seems to be well, but now when I get to the line
string fileName = in_file->d_name;
I have found that I don't access to the name of the file.
Anyone have any thoughts on this?
This is the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <opencv2/core/dirent.h>
#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
#include <conio.h>
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <strsafe.h>
#pragma comment(lib, "User32.lib")
#include <errno.h>
#include <iostream>
#include <time.h>
#include <limits.h>
#include <fstream>
#include <sys/stat.h>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/ml.hpp>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace cv::ml;
using namespace std;
int patchWidth = 15;
int patchHeight = 15;
int main(int, char**)
{
string imagesPath = "Images";
string resultsPath = "Patches";
DIR* FD;
struct dirent* in_file;
if (NULL == (FD = opendir (imagesPath.c_str())))
{
fprintf(stderr, "Error : Failed to open input directory\n");
return 0;
}
while ((in_file = readdir(FD)))
{
/* On linux/Unix we don't want current and parent directories
* If you're on Windows machine remove this two lines
*/
// if (!strcmp (in_file->d_name, "."))
// continue;
// if (!strcmp (in_file->d_name, ".."))
// continue;
/* Open directory entry file for common operation */
/* TODO : change permissions to meet your need! */
string fileName = in_file->d_name;
string pathFile = imagesPath;
pathFile.append("/");
pathFile.append(fileName);
//pathFile.append(".jpg");
Mat img = imread(pathFile.c_str());
Thanks in advance.
for a much simpler solution, just use cv::glob :
String imagesPath = "Images/*.png"; // it has filters, too !
vector<String> fn;
glob(path, fn, true); // recursive, if you want
for (size_t i=0; i<fn.size(); i++)
{
Mat img = imread(fn[i]);
...
}
I am trying to learn how to make a modular program. So what I want to do is read an array of integers.
Main:
#include <stdio.h>
#include <stdlib.h>
#define NMAX 10
void read (int *n, int a[NMAX]);
int main()
{
int n, a[NMAX];
read(&n,a);
return 0;
}
Then I saved this file 'read.cpp':
#include <stdio.h>
#include <stdlib.h>
#define NMAX 10
void read (int *n, int a[NMAX])
{
int i;
printf("dati n:\n");
scanf("%d",n);
for (i=1;i<=*n;i++)
{
printf("a[%d]= ",i);
scanf("%d\n",&a[i]);
}
}
read.cpp compiles succesfully, but when I compile the main function I get the error "no reference to read".
Include read.cpp when compiling.
g++ -o out main.cpp read.cpp
or
add #include "read.cpp" in main program
where i can find an sample code for hypertable or else can any one post an sample for hypertable with c++
If you meant the source code for hypertable
otherwise here is the manual
You can use this HQL tutorial or look at this example
see this:: http://blog.hypertable.com/
and download hypertable project :: http://www.hypertable.org/
#ifndef BOOST_FOREACH
#define BOOST_FOREACH 0
#endif
#include "Common/Compat.h"
#include "Common/System.h"
#include <arpa/inet.h>
#include <iostream>
#include <fstream>
#include "ThriftBroker/Client.h"
#include "ThriftBroker/gen-cpp/HqlService.h"
#include "ThriftBroker/ThriftHelper.h"
#include "ThriftBroker/SerializedCellsReader.h"
using namespace Hypertable;
using namespace Hypertable::ThriftGen;
int main (int argc, char **argv)
{
Thrift::Client *client = new Thrift::Client("localhost", 38080);
if (!client->namespace_exists("/"))
{
delete client;
return 0;
}
Namespace ns = client->namespace_open("/");
HqlResult result;
client->hql_query(result, ns, "select * from foo");
std::cout << result << std::endl;
client->namespace_close(ns);
delete client;
return 0;
}
将其和/opt/hypertable/current/include/ThriftBroker/gen-cpp文件夹下的
Client_constants.cpp、Client_types.cpp、ClientService.cpp、Hql_constants.cpp、Hql_types.cpp、HqlService.cpp一起编译