C++ Builder STL for OS X fails? - stl

Has anybody tried something as simple as #include <vector> in an application for the Mac compiled with XE2?
Is something so basic broken in XE2 update 1 for C++ Builder or is my install broken?
Simply adding #include <vector> to a new fire monkey HD app, I get build failures:
[BCC32 Error] cstdlib(43): E2015 Ambiguity between 'ldiv_t' and 'Posix::Stdlib::ldiv_t'
Full parser context
Unit1.cpp(7): #include C:\Program Files\Embarcadero\RAD Studio\9.0\include\boost_1_39\boost\tr1\tr1\vector
vector(16): #include C:\Program Files\Embarcadero\RAD Studio\9.0\include\boost_1_39\boost/tr1/detail/config_all.hpp
config_all.hpp(48): #include c:\program files\embarcadero\rad studio\9.0\include\dinkumware\cstdlib
cstdlib(32): namespace std
From the code:
//---------------------------------------------------------------------------
#include <fmx.h>
#pragma hdrstop
#include "Unit1.h"
#include <vector>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

Solution from Embarcadero (this is for update 2 only):
Open cstdlib in the [RADStudioXE2]\include\dinkumware directory
Take line 49: using _CSTD size_t; using _CSTD div_t; using _CSTD ldiv_t;
Move it above the "#if defined" block right above it (line 33)
The STL can now be compiled into an FMX C++ application

try removing $(CG_BOOST_ROOT) from your include paths.

Related

My C code won't compile against C code in a `.cu` file

I have 2 files that form a small CUDA library from my previous program (which works well, btw) written on C++.
The header for this library is:
#ifndef __cudaLU__
#define __cudaLU__
#include <assert.h>
#include <cuda_runtime.h>
#include <cusolverDn.h>
#include <cusolverSp.h>
#include <cusparse.h>
#include <cuComplex.h>
#include <stdlib.h>
void denseLS(int dim,
std::complex<float> * A,
std::complex<float> * b );
void sparseLS(int dim,
std::complex<float> *csrVal,
int *csrRowPtr,
int *csrColInd,
std::complex<float> *vecVal);
#endif
And I want to use this library in my old-as-the-hills C program just by setting procedure in the head of my main.c file:
extern void denseLS(int dim, float complex *A, float complex *b);
And it fails with a bunch of similar errors. Few of them are:
..NA/cudaLS.cu(115): error: namespace "std" has no member "complex"
..NA/cudaLS.cu(115): error: expected a ")"
..NA/cudaLS.cu(137): error: identifier "csrRowPtr" is undefined
..NA/cudaLS.cu(169): error: identifier "csrColInd" is undefined
..NA/cudaLS.cu(170): error: identifier "csrVal" is undefined
..NA/cudaLS.cu(171): error: identifier "vecVal" is undefined
I tried to make a change std::complex -> float complex and nothing works. Still same errors (without std error, ofc).
The cmake instructions file
cmake_minimum_required(VERSION 3.8)
project(NA)
set(CMAKE_C_STANDARD 11)
find_package(GSL REQUIRED)
find_package(CUDA REQUIRED)
include_directories("${CUDA_INCLUDE_DIRS}")
cuda_add_library(solvers STATIC
cudaLS.cu
cudaLS.h)
target_link_libraries(solvers ${CUDA_LIBRARIES} ${CUDA_cusparse_LIBRARY} ${CUDA_cusolver_LIBRARY})
target_compile_features(solvers PUBLIC cxx_std_11)
set_target_properties( solvers
PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
add_executable(NA main.c)
set_target_properties(NA PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(NA PRIVATE GSL::gsl m solvers)
What am I doing wrong pals?
UPD:
g++/gcc - 7.3
Linux
Well, I found what exactly I did in a wrong way.
Cmake is OK. But headers in the .h file have to be modified to
extern "C" void denseLS(int dim, cuComplex *A, cuComplex *b );
The cuda functions in .c have to be decleared in the head (or separate .h-file) as
void denseLS(int dim, float complex *A, float complex *b);

Memory mapping in Octave with mex-functions

I have a plain C code (running on Linux) and I would like to implement it in Octave, so I thought I could use a mex-file for handling the memory mapping and send the information I received (or send) back and forth to my script in Octave and my sensors. The C code looks like this:
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <poll.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <sys/mman.h>
#define CUSTOM_IP_MAP_SIZE 0x10000
#define CUSTOM_IP_BASEADDR 0x43C00000
#define CUSTOM_IP_S00_AXI_SLV_REG0_OFFSET 0
#define CUSTOM_IP_S00_AXI_SLV_REG1_OFFSET 4
int main(void)
{
uint32_t leds=0x0;
int fd = open("/dev/uio0", O_RDWR);
void *ptr;
if (fd < 0) {
perror("open");
exit(EXIT_FAILURE);
}
ptr = mmap(NULL, CUSTOM_IP_MAP_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
while (1) {
leds = *((unsigned *)(ptr + CUSTOM_IP_S00_AXI_SLV_REG1_OFFSET)); //Read from the IP (slv_reg1).
*((unsigned *)(ptr + CUSTOM_IP_S00_AXI_SLV_REG0_OFFSET)) = leds; //Write to the IP (slv_reg0).
}
close(fd);
exit(EXIT_SUCCESS);
}
I compiled the code with no errors and the following command:
mkoctfile --mex mmap.c
I get the following error when I run it in Octave:
error: failed to install .mex file function 'mmap'
Should I keep trying to do this with a mex-function or there is other option better for this?
Thank you for any help.

undefined reference to cusolverDn

I am trying to run the cuSolver library available in cuda 7.0. I have an issue with using the cuSolver library that must be very simple to fix, but here I am asking for some help.
I have looked at quite a few examples posted around and I chose in particular this one from JackOLantern:
Parallel implementation for multiple SVDs using CUDA
I have just reduced it to a kernel_0.cu:
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include<iostream>
#include<iomanip>
#include<stdlib.h>
#include<stdio.h>
#include<assert.h>
#include<math.h>
#include <cusolverDn.h>
#include <cuda_runtime_api.h>
#include "Utilities.cuh"
/********/
/* MAIN */
/********/
int main(){
// --- gesvd only supports Nrows >= Ncols
// --- column major memory ordering
// --- cuSOLVE input/output parameters/arrays
int *devInfo; gpuErrchk(cudaMalloc(&devInfo, sizeof(int)));
// --- CUDA solver initialization
cusolverDnHandle_t solver_handle;
cusolverDnCreate(&solver_handle);
cusolverDnDestroy(solver_handle);
return 0;
}
I use the same Utilities.cuh and Utilities.cu as JackOlantern. I compile it as (to be explicit):
/usr/local/cuda-7.0/bin/nvcc kernel_0.cu Utilities.cu
And what I get is:
Utilities.cu(27): warning: conversion from a string literal to "char *" is deprecated
Utilities.cu(27): warning: conversion from a string literal to "char *" is deprecated
/tmp/tmpxft_00007e1d_00000000-22_kernel_0.o: In function `main':
tmpxft_00007e1d_00000000-4_kernel_0.cudafe1.cpp:(.text+0x3d): undefined reference to `cusolverDnCreate'
tmpxft_00007e1d_00000000-4_kernel_0.cudafe1.cpp:(.text+0x49): undefined reference to `cusolverDnDestroy'
collect2: error: ld returned 1 exit status
If I comment out the cusolverDnCreate and cusolverDnDestroy, it compiles fine, so the library is apparently well included.
What simple and basic point am I missing? I have searched around, but I could not fix it. Thanks there.
What simple and basic point am I missing?
You have to link against the cusolver library:
/usr/local/cuda-7.0/bin/nvcc kernel_0.cu Utilities.cu -lcusolver

cuda Texture declaration compile-time error

I'm trying to compile the following piece of code:
#include <stdio.h>
#include <time.h>
#include <cuda.h>
#include <cuda_runtime_api.h>
texture<float, 2, cudaReadModeElementType> tex;
int main () { ... }
yet, nvcc gives me the following error:
main.c:6:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
I'm pretty new to CUDA, so I suppose I'm missing something here.
You can only use CUDA syntax in .cu files.

stl copy () iterator: binary '>>' : no operator found

Here I have a basic example from a pdf on STL.
Why doesn't it work?
#include "stdafx.h"
#include <vector>
#include <algorithm>
#include <iostream>
#include <iterator>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector<string> coll;
copy(istream_iterator<string>(cin), //start of source
istream_iterator<string>(), //end of source
back_inserter(coll));
return 0;
}
errors:
ClCompile: All outputs are up-to-date.
stl_testing1.cpp
c:\program files\microsoft visual studio 10.0\vc\include\iterator(470): error C2678: binary '>>' :
no operator found which takes a left-hand operand of type 'std::basic_istream<_Elem,_Traits>' (or there is no acceptable conversion)
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 10.0\vc\include\istream(1053): could be 'std::basic_istream<_Elem,_Traits> &std::operator
>><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,signed char *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 10.0\vc\include\istream(1060): or 'std::basic_istream<_Elem,_Traits> &std::operator
>><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,signed char &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 10.0\vc\include\istream(1067): or 'std::basic_istream<_Elem,_Traits> &std::operator
>><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,unsigned char *)'
with
I wonder what is wrong. This is a Win32 console application.
#include <string>
This might help.