Visual Studio Linux cannot find host global? - c++

Attempting to build netcode server.c example using visual studio for linux. During compilation I am receiving the following error:
netcode.c(5194,24): error : ‘CLOCK_MONOTONIC_RAW’ undeclared (first use in this function)
Which is coming from the following source:
// linux
#include <unistd.h>
void netcode_sleep( double time )
{
struct timespec ts;
ts.tv_sec = (time_t) time;
ts.tv_nsec = (long) ((time - (double) ( ts.tv_sec )) * 1000000000.0);
nanosleep( &ts, NULL );
}
double netcode_time()
{
static double start = -1;
if ( start == -1 )
{
struct timespec ts;
clock_gettime( CLOCK_MONOTONIC_RAW, &ts );
start = ts.tv_sec + ( (double) ( ts.tv_nsec ) ) / 1000000000.0;
return 0.0;
}
struct timespec ts;
clock_gettime( CLOCK_MONOTONIC_RAW, &ts );
double current = ts.tv_sec + ( (double) ( ts.tv_nsec ) ) / 1000000000.0;
return current - start;
}
I have successfully built this project on windows, as well as DIRECTLY on a linux machine before with no issue. I'm a little perplexed as I wasn't expecting to run into any issues since from what I can tell visual studio for linux is really just syncing sources with a linux host and sending a g++ command for everything to be compiled on the host...so not real sure why this is happening. Any ideas?
EDIT
Solution was to include #define _POSIX_C_SOURCE 199309L in the source file of the library. For some reason this is not required when building directly on the linux machine, but visual studio for linux is requiring it. I'm guessing that maybe the compile command generated by visual studio for linux is possibly doing something to ommit the build from using _POSIX_C_SOURCE? Maybe? (making this assumption based on the fact the project built successfully directly on the linux machine using a basic g++ command: g++ server.c netcode.a -lsodium)
Can anyone identify such a switch/option that would be causing that from the below (which is generated by visual studio)
"g++" -W"switch"
-W"no-deprecated-declarations"
-W"empty-body"
-W"conversion"
-W"return-type"
-W"parentheses"
-W"no-pointer-sign"
-W"no-format"
-W"uninitialized"
-W"unreachable-code"
-W"unused-function"
-W"unused-value"
-W"unused-variable"
-std=c++11
-Wall -fno-strict-aliasing
-g2 -gdwarf-2 "g++" -O0 "3600000" -fthreadsafe-statics
-W"switch"
-W"no-deprecated-declarations"
-W"empty-body"
-W"conversion"
-W"return-type"
-W"parentheses"
-W"no-format"
-W"uninitialized"
-W"unreachable-code"
-W"unused-function"
-W"unused-value"
-W"unused-variable"
-frtti -fno-omit-frame-pointer -std=c11 -fexceptions -o "C:\dev\project<different options>

Related

Building Intel IPP with MingW

I'm trying to use Intel IPP with MingW(mingw-w64\x86_64-8.1.0) using NetBeans 12.2 and also tried with Eclipse 2021-06 (4.20.0) in Win10. Specified the include("C:/Program Files (x86)/Intel/oneAPI/ipp/2021.3.0/include") and dll's("C:/Program Files (x86)/Intel/oneAPI/ipp/2021.3.0/redist/ia32") path in the project settings.
For the below sample code,
#include <iostream>
#include <ipp.h>
using namespace std;
int main(int argc, char** argv)
{
const IppLibraryVersion *lib;
IppStatus status;
Ipp64u cpuFeatures, enabledFeatures;
Ipp8u *gray= NULL;
IppiSize size;
IplImage* img = NULL; // new IplImage structure img
/* Init IPP library */
ippInit(); /* Initialize Intel(R) IPP library */
lib = ippGetLibVersion();/* Get Intel(R) IPP library version info */
printf("%s %s\n", lib->Name, lib->Version);
return 0;
}
I'm getting error,
Error: 'IplImage' was not declared in this scope;
Also, on commenting the line :IplImage* img = NULL; I get the following error,
g++ -o dist/Debug/MinGW-Windows/samplecppapplication
build/Debug/MinGW-Windows/main.o -L"C:/Program\ Files
(x86)/Intel/oneAPI/ipp/2021.3.0/redist/ia32" -lippcc -lippccg9
-lippcch9 -lippccp8 -lippccs8 -lippccw7 -lippch -lippchg9 -lippchh9 -lippchp8 -lippchs8 -lippchw7 -lippcore -lippcv -lippcvg9 -lippcvh9 -lippcvp8 -lippcvs8 -lippcvw7 -lippdc -lippdcg9 -lippdch9 -lippdcp8 -lippdcs8 -lippdcw7 -lippe -lippeg9 -lippeh9 -lippep8 -lippes8 -lippew7 -lippi -lippig9 -lippih9 -lippip8 -lippis8 -lippiw7 -lipps -lippsg9 -lippsh9 -lippsp8 -lippss8 -lippsw7 -lippvm -lippvmg9 -lippvmh9 -lippvmp8 -lippvms8 -lippvmw7 c:/MuTest/MinGW/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe:
cannot find -lippcc
c:/MuTest/MinGW/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe:
cannot find -lippccg9
c:/MuTest/MinGW/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe:
cannot find -lippcch9 .... ...
Can you please help in fixing this and get to work using IPP ?
I tried the ipp sample with g++ compiler which comes with mingw-w64\x86_64-8.1.0 in windows10 command prompt(initialize oneapi environment before compiling the code) and it worked fine (after commenting the line :IplImage* img = NULL). I've included libraries from intel64 folder in ipp directory which comes with oneapi, as i'm using 64 bit windows machine.
g++ test.cpp -o ipptest -I "C:\Program Files (x86)\Intel\oneAPI\ipp\2021.3.0/include" -L "C:\Program Files (x86)\Intel\oneAPI\ipp\2021.3.0\redist\intel64" -lippcore

C++ CodeBlocks upgrade to C++17 can't use std::filesystem

I need to be able to list the files in a directory, and so I'm trying to upgrade my C++ version in CodeBlocks to C++ 17 so i can use filesystem. To do this I followed the steps outlined at http://candcplusplus.com/enable-c17-in-code-blocks-mingw-gcc-for-all-version-with-pictures#:~:text=Enabling%20the%20C%2B%2B17,Create%20a%20project.
I didnt have to change much, CodeBlocks 20.03 and MinGW 8.1.0 are already installed. MinGW is already in my path from when I built wxWidgets. The Settings->Compiler...->Toolchain executables tab I didnt have to make any changes to, and appears in CodeBlocks as:
I also checked the box to use C++ 17 in compiler settings like so
I ran the test program on the website with the instructions and got "True!".
However when I change the basic test program to this, to try and use filesystem to read files in a directory, I get an error:
#include <iostream>
#include <filesystem>
using namespace std;
int main()
{
const int i=90;
if constexpr (i) //'if constexpr' is part of C++17
{
cout << "True!";
}
else
{
cout<<"False" ;
}
std::string path = "../MagicProgCPP/files/debug images/";
for (const auto & entry : filesystem::directory_iterator(path))
{
cout << entry.path() << std::endl;
}
cin.get();
return 0;
}
The program stops building, opens the file fs_path.h and stops on this line:
#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
if (__p.is_absolute()
|| (__p.has_root_name() && __p.root_name() != root_name())) <----- ******STOPS HERE
operator=(__p);
else
{
string_type __pathname;
if (__p.has_root_directory())
__pathname = root_name().native();
else if (has_filename() || (!has_root_directory() && is_absolute()))
__pathname = _M_pathname + preferred_separator;
__pathname += __p.relative_path().native(); // XXX is this right?
_M_pathname.swap(__pathname);
_M_split_cmpts();
}
#else
// Much simpler, as any path with root-name or root-dir is absolute.
if (__p.is_absolute())
operator=(__p);
else
{
if (has_filename() || (_M_type == _Type::_Root_name))
_M_pathname += preferred_separator;
_M_pathname += __p.native();
_M_split_cmpts();
}
#endif
return *this;
}
I get this error in the build log:
C:\Program Files\CodeBlocks\MinGW\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\bits\fs_path.h|237|error: no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')|
I'm prety confident the path exists as I entered it and there's files in it. The build log message suggests maybe I'm not using C++17? But when I click build, this is the line the program uses to build:
g++.exe -Wall -fexceptions -g -Wall -std=c++17 -c E:\testc17\main.cpp -o obj\Debug\main.o
What am I doing wrong? Thanks
The bug 78870 was fixed since 2018-07.
You should add to project options -> linker settings -> link libraries the following library: stdc++fs.
I tried to compile your code with MinGW gcc 8.1.0 (via CodeBlocks) and everything works well (clearly with another path, since I don't have the same directories as you).
You could also add a check on the existence of the search directory like this:
namespace fs = std::filesystem;
std::string mypath { "../MyDir" };
if(fs::exists(mypath))
{
for(const auto & entry : fs::directory_iterator(path))
{
cout << entry.path() << std::endl;
}
}
It appears that this exact problem is a known bug in mingw 8.1. The bug report is here: https://sourceforge.net/p/mingw-w64/bugs/737/
and has the error in the same location:
operator != is declared and defined in line 550, but referenced in line 237.
The problem is triggered by operator/= in line 233:
path& operator/=(const path& __p)
{
#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
if (__p.is_absolute()
|| (__p.has_root_name() && __p.root_name() != root_name()))
operator=(__p);
else
{
string_type __pathname;
if (__p.has_root_directory())
__pathname = root_name().native();
else if (has_filename() || (!has_root_directory() && is_absolute()))
__pathname = _M_pathname + preferred_separator;
__pathname += __p.relative_path().native(); // XXX is this right?
_M_pathname.swap(__pathname);
_M_split_cmpts();
}
The bug report said this was fixed in master meaning you need to install a version of mingw with the fix applied. I believe the best method is to upgrade mingw to a version greater than 8.1
user4581301 commented above in the main question that the following link has instructions on how to get a mingw install: How to install MinGW-w64 and MSYS2?

When using dyn.load in R I do not get any error messages, but my .dll file does not load

I am following an example from the 'Writing R extensions manual' version 3.3.1. Specifically, I am working with c++ code, which I have saved in file out.cpp, that is on page 115 of that manual shown below:
#include <R.h>
#include <Rinternals.h>
SEXP out(SEXP x, SEXP y)
{
int nx = length(x), ny = length(y);
SEXP ans = PROTECT(allocMatrix(REALSXP, nx, ny));
double *rx = REAL(x), *ry = REAL(y), *rans = REAL(ans);
for(int i = 0; i < nx; i++) {
double tmp = rx[i];
for(int j = 0; j < ny; j++)
rans[i + nx*j] = tmp * ry[j];
}
UNPROTECT(1);
return ans;
}
I have a windows computer and use cygwin command line. There I typed R CMD SHLIB out.cpp and get the following result:
cygwin warning:
MS-DOS style path detected: C:/R-3.2.3/etc/x64/Makeconf
Preferred POSIX equivalent is: /cygdrive/c/R-3.2.3/etc/x64/Makeconf
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
g++ -m64 -I"C:/R-3.2.3/include" -DNDEBUG -I"d:/RCompile/r- compiling/local/local323/include" -O2 -Wall -mtune=core2 -c out.cpp -o out.o
g++ -m64 -shared -s -static-libgcc -o out.dll tmp.def out.o -Ld:/RCompile/r-compiling/local/local323/lib/x64 -Ld:/RCompile/r-compiling/local/local323/lib -LC:/R-3.2.3/bin/x64 -lR
I think there is nothing wrong with this, right? Then when I go into Rstudio I type
dyn.load(paste("C:/Rextensions/out",
.Platform$dynlib.ext, sep = ""),local=FALSE)
which gives me no error message whatsoever. But when I run
is.loaded('out')
I get 'FALSE', so I am never able to upload out.dll. Could you help me with this please?
P.S.: I know how to run functions like this one using Rcpp, so please don't tell me to do that instead. What I am trying to do is understand really well the Writing Extensions manual so I hope I can go through all of their examples in that document.
Thank you.

Can't debug cpp code under Qt Creator when linking with CUDA libs

I have a problem with debugging a simple cpp code (it call some CUDA functions like cuInit(), cuDeviceGetCount()..). When I put a break point into the CPP code and start debugging I get this message:
This does not seem to be a "Debug" build.
When I remove all CUDA-calls and do not link the program against the cuda.lib and cudart.lib then the code is debuggable (it is possible to stop the program at the breakpoint and no error message is displayed).
Here is my CPP code:
#include <QtCore/QCoreApplication>
#include <QDebug>
#include <cuda.h>
#include <builtin_types.h>
int main(int argc, char* argv [])
{
QCoreApplication(argc, argv);
int deviceCount = 0;
int cudaDevice = 0;
char cudaDeviceName [100];
cuInit(0);
cuDeviceGetCount(&deviceCount);
cuDeviceGet(&cudaDevice, 0);
cuDeviceGetName(cudaDeviceName, 100, cudaDevice);
qDebug() << "Number of devices: " << deviceCount;
qDebug() << "Device name:" << cudaDeviceName;
}
Here is my .pro file:
QT += core
QT -= gui
TARGET = cudatest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
#################################
# Begin CUDA configuration
win32 {
CUDA_PATH = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v6.5"
CUDA_INC_DIR = $$CUDA_PATH/include
contains(QMAKE_TARGET.arch, x86_64) {
SYSTEMNAME = x64
SYSTEMTYPE = 64
} else {
SYSTEMNAME = Win32
SYSTEMTYPE = 32
}
CUDA_LIB_DIR = $$CUDA_PATH/lib/$$SYSTEMNAME
QMAKE_CXXFLAGS_RELEASE -= -MD
QMAKE_CXXFLAGS_RELEASE += -MT
QMAKE_CXXFLAGS_DEBUG -= -MDd
QMAKE_CXXFLAGS_DEBUG += -MTd
}
INCLUDEPATH += $$CUDA_INC_DIR
LIBS += -L$$CUDA_LIB_DIR -lcuda -lcudart
#End CUDA configuration
########################
Environment:
Qt Creator 3.2.2
CUDA v6.5
CPP Compiler: VC++ 2013 Express
Debugger: C:\Program Files (x86)\Windows Kits\8.1\Debuggers\x86\cdb.exe
Qt 5.3.2 (compiled by VC++ 2013, 32bit)
I tried to do the same with VC++ 2010 Proffesional with the same result.
Can anyone give me a suggestion where could be the problem?
Thank you.
its probably because you are using Visual Express 2013. It says here that there is no compiler support for VS 2013 Express for CUDA v6.5(Under the Table 2. Windows Compiler Support in CUDA 6.5) You need to install the complete version of Visual Studio.

How to tell netbeans information on pthread_barrier_t

I can't seem to get netbeans to recognize the pthread_barrier_t type. I can type in #include<pthread.h> okay, but no luck on pthread_barrier_t.
The following is the build and the error:
g++ -lpthread -c -g -MMD -MP -MF build/Debug/GNU-MacOSX/main.o.d -o
build/Debug/GNU-MacOSX/main.o main.cpp main.cpp:32: error:
'pthread_barrier_t' does not name a type
I am using Netbeans 7.1 and I am on Mac OSX 10.7.2
I can create threads without any compile issues.
bool isNotInSteadyState()
{
int rc = 0;
threadData threadDataArray[NUM_THREADS];
int dataArrayCount = 0;
if (NUM_THREADS < ((PLATE_SIZE - 2) * (PLATE_SIZE - 2)))
{
for (int i = 1; i < PLATE_SIZE - 1; i += sqrt(NUM_THREADS))
{
for (int j = 1; j < PLATE_SIZE - 1; j += sqrt(NUM_THREADS))
{
threadDataArray[dataArrayCount].endY = i + sqrt(NUM_THREADS) - 1;
threadDataArray[dataArrayCount].x = i;
threadDataArray[dataArrayCount].endY = j + sqrt(NUM_THREADS) - 1;
threadDataArray[dataArrayCount++].y = j;
pthread_t* thread;
int pthread_create(thread, NULL,isNotInSteadyStateCheckRunInParallel, &threadDataArray[dataArrayCount]);
if (dataArrayCount >= NUM_THREADS)
{
//pthread_barrier_init(pthread_barrier_t * barrier,
//const pthread_barrierattr_t *restrict attr, NUM+THREADS);
}
if (rc != 0)
{
fprintf(stderr, "Steady State check failed!\n");
}
}
}
}
}
Thoughts?
Thanks,
According to info about pthread_barriers on opengroup.org, barriers are defined in the optional part of POSIX 1003.1 edition 2004; the name of option is "(ADVANCED REALTIME THREADS)", sometimes more exact referred as "BAR, barriers (real-time)".
All POSIX options are listed here
2.1.3 POSIX Conformance
POSIX System Interfaces
The system may support one or more options (see Options) denoted by the following symbolic constants:
_POSIX_BARRIERS
So, only if the _POSIX_BARRIERS macro is defined as positive number, you can use pthread_barrier_t or pthrad_barrier_wait.
Mac OS X is POSIX Compliant, but I can't find full list of options implemented. I know that Solaris has problems with pthread_barrier too. There is a post in apple mainling list from 2006. It says that there are no barriers in Mac OS X