How to compile Poco with cygwin? - cygwin

I have Downloaded the POCO from the mirror site and when I am compiling the it not able to link the library ?
Example
#include "Poco/Timestamp.h"
#include<iostream>
#include <ctime>
using Poco::Timestamp;
int main(int argc, char** argv)
{
Timestamp now; // the current date and time
std::time_t t1 = now.epochTime(); // convert to time_t ...
Timestamp ts1(Timestamp::fromEpochTime(t1)); // ... and back again
for (int i = 0; i < 100000; ++i) ; // wait a bit
Timestamp::TimeDiff diff = now.elapsed(); // how long did it take?
Timestamp start(now); // save start time
now.update(); // update with current
time
diff = now - start; // again, how long?
return 0;
}
compilation error
$ g++ pocoDemo.cpp
pocoDemo.cpp:1:10: fatal error: Poco/Timestamp.h: No such file or directory
compilation terminated.

Related

Get function from x64 instruction pointers?

This is an exercise that I want to implement in real code
I send a signal to my app (x86-64 linux). My app then executes code that walks the stack and prints out instruction pointers. I'm not sure if I want only the last few or everything to main. Anyway, I'm releasing an optimized binary without debug information. I strip symbols before its distributed.
I was wondering, how do I translate it back? I don't need to translate it in the app. I can use the machine I build to go from rip's to functions. I was thinking maybe I should also distribute one with debug information and maybe have the user be able to see the function+line but I think line will be unlikely if its optimized well
Another problem I have is my code doesn't seem to walk past the signal function. backtrace figures it out but I'm trying to do this without libc. Here's some code
#include <signal.h>
#include <cstdio>
typedef unsigned long long u64;
int mybacktrace();
#include <execinfo.h>
#include <unistd.h>
void print_stacktrace(void) {
size_t size;
enum Constexpr { MAX_SIZE = 1024 };
void *array[MAX_SIZE];
size = backtrace(array, MAX_SIZE);
backtrace_symbols_fd(array, size, STDOUT_FILENO);
}
void mysig(int signo) {
mybacktrace();
_exit(1);
}
int mybacktrace() {
u64*p;
p = (u64*)((u64)&p + 16); //seems to work correctly
for (int i = 0; i < 10 && (u64)p >= 1<<16; i++)
{
printf("%d %p\n", i, p[1]);
p = (u64*)(p[0]);
}
print_stacktrace(); return 0;
return 0;
}
int test()
{
return mybacktrace();
}
int main(int argc, char *argv[])
{
signal(SIGILL, mysig);
test();
__builtin_trap();
return 0;
}

Why am I not getting any input from this slurm job?

I am in a distributed and parallel computing class and we have to log into the Alabama Supercomputer and run a hello world for Open MP. I run it and the program compiles but there is no text in the output file other than data about the run time. What am I doing wrong? I compile it to an executable that I then put in the .sh file. Is this wrong?
My c file and my .sh file look like this.
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
void Hello(void);
int main(int argc, char* argv[]){
int thread_count = strtol(argv[1], NULL, 10);
# pragma omp parallel num_threads(thread_count)
Hello();
return 0;
}
void Hello(void){
int my_rank = omp_get_thread_num();
int thread_count = omp_get_num_threads();
printf("Hello from thread %d of %d\n", my_rank, thread_count);
}
#!/bin/sh
export OMP_NUM_THREADS=15
./OpenMPHello
Why does it run in the system but produce no output?

segmentation fault in a C code

I have written a C code yesterday which works fine. Now I want to make some changes in the file, so I just copy this code in a new file. Compilation of new file is just fine, but when I try to run my executable file, I am getting segmentation fault. However my previous code is working. Initially I thought it's a permission issue so I change the permission of executable using chmod 777. But still I am getting segmentation fault. Here is my code:-
#include <stdio.h>
#include <time.h>
void pauseSec(int sec);
int main() {
FILE *io,*iodir,*ioval,*iodir_S,*ioval_S,*io_S,*iodir_P,*ioval_P,*io_P;
io = fopen("/sys/class/gpio/export", "w");
fseek(io,0,SEEK_SET);
fprintf(io,"%d",15);
fflush(io);
iodir = fopen("/sys/class/gpio/gpio15/direction", "w");
fseek(iodir,0,SEEK_SET);
fprintf(iodir,"out");
fflush(iodir);
while(1)
{
fprintf(ioval,"%d",1);
fflush(ioval);
pauseSec(1);
fprintf(ioval,"%d",0);
fflush(ioval);
pauseSec(1);
}
fclose(io);
fclose(iodir);
fclose(ioval);
return 0;
}
void pauseSec(int sec) {
time_t now,later;
now = time(NULL);
later = time(NULL);
while((later - now) < (double)sec)
later = time(NULL);
}
I wonder why same code is behaving differently when written in two different file. What can be the reason for this?
Got the issue, forget to initialize ioval. Correct code is here:-
#include <stdio.h>
#include <time.h>
void pauseSec(int sec);
int main() {
FILE *io,*iodir,*ioval,*iodir_S,*ioval_S,*io_S,*iodir_P,*ioval_P,*io_P;
io = fopen("/sys/class/gpio/export", "w");
fseek(io,0,SEEK_SET);
fprintf(io,"%d",15);
fflush(io);
iodir = fopen("/sys/class/gpio/gpio15/direction", "w");
fseek(iodir,0,SEEK_SET);
fprintf(iodir,"out");
fflush(iodir);
ioval = fopen("/sys/class/gpio/gpio15/value", "w");
while(1)
{
fprintf(ioval,"%d",1);
fflush(ioval);
pauseSec(1);
fprintf(ioval,"%d",0);
fflush(ioval);
pauseSec(1);
}
fclose(io);
fclose(iodir);
fclose(ioval);
return 0;
}
void pauseSec(int sec) {
time_t now,later;
now = time(NULL);
later = time(NULL);
while((later - now) < (double)sec)
later = time(NULL);
}

seperate the cuda host code in .cpp file

main.cpp
#include<iostream>
#include "cuda.h"
using namespace std;
void cuda_calculation();
int main()
{
cuda_calculation();
return 0;
}
cu.h
void call(int , int ,float* , int );
cuda.cpp
#include <stdio.h>
#include <cuda.h>
#include "cu.h"
void cuda_calculation()
{
float *a_h, *a_d; // Pointer to host & device arrays
const int N = 10; // Number of elements in arrays
size_t size = N * sizeof(float);
a_h = (float *)malloc(size); // Allocate array on host
cudaMalloc((void **) &a_d, size); // Allocate array on device
// Initialize host array and copy it to CUDA device
for (int i=0; i<N; i++) a_h[i] = (float)i;
cudaMemcpy(a_d, a_h, size, cudaMemcpyHostToDevice);
// Do calculation on device:
int block_size = 4;
int n_blocks = N/block_size + (N%block_size == 0 ? 0:1);
void call(n_blocks, block_size,&a_d, N);
/*square_array <<< n_blocks, block_size >>> (a_d, N);*/
// Retrieve result from device and store it in host array
cudaMemcpy(a_h, a_d, sizeof(float)*N, cudaMemcpyDeviceToHost);
// Print results
for (int i=0; i<N; i++) printf("%d %f\n", i, a_h[i]);
// Cleanup
free(a_h); cudaFree(a_d);
}
cu.cu
#include <stdio.h>
#include "cu.h"
#include <cuda.h>
// Kernel that executes on the CUDA device
__global__ void square_array(float *a, int N)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx<N) a[idx] = a[idx] * a[idx];
}
//}
void call(int a,int b,float* c,int d)
{
square_array <<< 3,4 >>> (c,d);
}
I tried to seperate the kernal code and host code in a cpp file, however the following error prevails:
Error 'cudaMemcpy': identifier not found and the other cuda related identifier is not identified.
how to use the cuda related identifier in cpp file and call the kernal functions
There are some errors: void cuda_calculation(); needs to be visible to main.cpp through a header file (cu.h).
Also make sure to compile your .cu files with nvcc and NOT as a standard C++ file. Use CUDA compilation rules to make this process easy (installed by default as part of CUDA toolkit)
after a long trial ,I came with the proper output,
to include the cuda identifier in the cpp files we not only need to include cuda.h but also we need to include cuda_runtime.h as
cuda.cpp as
#include <stdio.h>
#include <cuda.h>
#include<cuda_runtime.h>
#include "cu.h"
#include "cud.h"
//void call(int , int ,float * , int );
void cuda_calculation()
{
float *a_h, *a_d; // Pointer to host & device arrays
const int N = 10; // Number of elements in arrays
size_t size = N * sizeof(float);
a_h = (float *)malloc(size); // Allocate array on host
cudaMalloc((void **) &a_d, size); // Allocate array on device
// Initialize host array and copy it to CUDA device
for (int i=0; i<N; i++) a_h[i] = (float)i;
cudaMemcpy(a_d, a_h, size, cudaMemcpyHostToDevice);
// Do calculation on device:
int block_size = 4;
int n_blocks = N/block_size + (N%block_size == 0 ? 0:1);
call(n_blocks, block_size,a_d, N);
/*square_array <<< n_blocks, block_size >>> (a_d, N);*/
// Retrieve result from device and store it in host array
cudaMemcpy(a_h, a_d, sizeof(float)*N, cudaMemcpyDeviceToHost);
// Print results
for (int i=0; i<N; i++) printf("%d %f\n", i, a_h[i]);
// Cleanup
free(a_h);
cudaFree(a_d);
}
so the others files are
main.cpp
#include<iostream>
#include "cud.h"
using namespace std;
int main()
{
cuda_calculation();
return 0;
}
cud.h
void cuda_calculation();
cu.h
void call(int , int ,float* , int );
cu.cu
#include <stdio.h>
#include "cu.h"
#include <cuda.h>
// Kernel that executes on the CUDA device
__global__ void square_array(float *a, int N)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx<N) a[idx] = a[idx] * a[idx];
}
//}
void call(int a,int b,float* c,int d)
{
square_array <<< 3,4 >>> (c,d);
}

How do I set up a function to convert vector of strings to vector of integers in VC++?

The question is in the title. Need help figuring out why my code compiles but doesn't work as intended. Thanks!
//This example demonstrates how to do vector<string> to vectro<int> conversion using a function.
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
vector<int>* convertStringVectorToIntVector (vector<string> *vectorOfStrings)
{
vector<int> *vectorOfIntegers = new vector<int>;
int x;
for (int i=0; i<vectorOfStrings->size(); i++)
{
stringstream str(vectorOfStrings->at(i));
str >> x;
vectorOfIntegers->push_back(x);
}
return vectorOfIntegers;
}
int main(int argc, char* argv[]) {
//Initialize test vector to use for conversion
vector<string> *vectorOfStringTypes = new vector<string>();
vectorOfStringTypes->push_back("1");
vectorOfStringTypes->push_back("10");
vectorOfStringTypes->push_back("100");
delete vectorOfStringTypes;
//Initialize target vector to store conversion result
vector<int> *vectorOfIntTypes;
vectorOfIntTypes = convertStringVectorToIntVector(vectorOfStringTypes);
//Test if conversion is successful and the new vector is open for manipulation
int sum = 0;
for (int i=0; i<vectorOfIntTypes->size(); i++)
{
sum+=vectorOfIntTypes->at(i);
cout<<sum<<endl;
}
delete vectorOfIntTypes;
cin.get();
return 0;
}
The code above has only one problem: You are deleting your vectorOfStringTypes before you pass it to your conversion function.
Move the line delete vectorOfStringTypes; to after you have called your convert function and the program works as intended.

Resources