CLion C++ fatal error: 'process.h' file not found - c++

When I use CLion on a Mac to compile C++ code for highlight removal in a single image, there is an error:
Please help me fix it.
#ifndef QX_CVPR09_CTBF_BASIC_H
#define QX_CVPR09_CTBF_BASIC_H
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <numeric>
#include <vector>
#include <process.h>
#include <direct.h>
#include <io.h>
#include <time.h>
#include <string>
#include <memory.h>
#include <algorithm>
#include <functional> // For greater<int>()
#include <iostream>
#if _MSC_VER > 1020 // if VC++ version is > 4.2
using namespace std; // std c++ libs implemented in std
#endif
#define QX_DEF_PADDING 10
#define QX_DEF_THRESHOLD_ZERO 1e-6
class qx_timer {public: void start(); float stop(); void time_display(char *disp=""); void fps_display(char *disp=""); private: clock_t m_begin; clock_t m_end;};
It's a part of my code. The full code is too long.

process.h
process.h is a C header file which contains function declarations and
macros used in working with threads and processes. Most C compilers
that target DOS, Windows 3.1x, Win32, OS/2, Novell NetWare or DOS
extenders supply this header and the library functions in their C
library. Neither the header file nor most of the functions are defined
by either the ANSI/ISO C standard or by POSIX.
Depends on which platform you compile and what standard you use. If you are on linux or compile with c99/ansi standard then this header will probably just not be available (which might be your error)

Related

Adding Winsock2 to my MinGW-w64 C/C++ causes: undefined reference to `InitializeConditionVariable'

When I add winsock2 to my MinGW-w64 C/C++ project, it then gets make error:
undefined reference to `InitializeConditionVariable'.
NOTE: InitializeConditionVariable built and ran ok prior to adding Winsock.
main.c ...
#undef UNICODE
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "infrastructure.h"
#include "common.h"
#include "bg.h"
#include "aox.h"
#include <windows.h>
#include <ws2tcpip.h>
#include <synchapi.h>
. . .
static void mutexInit()
{
#ifdef WINDOWS
// Initialize critical sections and condition variables
InitializeCriticalSection(&iqSamplesCriticalSection);
InitializeCriticalSection(&bgBufferCriticalSection);
InitializeConditionVariable(&newSamplesAvailable); <<<<<<<<<<<<<<<<<<< ERROR: undefined reference
#else
// Initialize mutexes
pthread_mutex_init(&iqSamplesCriticalSection, NULL);
pthread_mutex_init(&bgBufferCriticalSection, NULL);
pthread_cond_init(&newSamplesAvailable,NULL);
#endif
}
InitializeConditionVariable() has nothing to do with WinSock. This is strictly an issue with your own code.
InitializeConditionVariable() was introduced in Windows Vista. You are likely just linking to an out-dated kernel32.lib that doesn't expose newer Vista+ APIs. So, you can either:
update the Windows SDK for your compiler.
load the various ConditionVariable functions dynamically at runtime using GetProcAddress().

std::queue included in precompiled header is not part of namespace std

I have a problem with the inclusion of header "queue" via a precompiled header file in c++ (VS 2019).
My Visual Studio solution consists of two projects, one engine project (static library) and one sandbox project (links the engine project) to test the engine's functionality. The engine project uses a precompiled header file, in which i just included "queue" since i am implementing a message system. Both projects are using C++17.
Visual Studio compiles the engine project without a problem, the sandbox project then throws the following error while compiling:
Error C2039 'queue': is not a member of 'std' (path\to\engine\message_handler.h)
As soon as I include "queue" directly in message_handler.h (see code excerpt), the error vanishes and the project starts up just fine.
I have been using the precompiled header for almost a year now and never had any problems.
Can anyone help me with this?
Following are the relevant excerpts from my code.
Precompiled header:
#pragma once
//memory
#include <memory>
//timing
#include <chrono>
#include <ctime>
//container
#include <vector>
#include <queue>
#include <unordered_map>
#include <array>
//string and streams
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
//misc
#include <algorithm>
#include <cstdint>
#include <cmath>
#include <random>
message.h
struct Message
{
Message(){}
uint32_t id_;
};
message_handler.h
#pragma once
//#include <queue> //fixes the issue
#include "message.h"
using UnqPtr = std::unique_ptr<Message>;
class MessageHandler
{
public:
MessageHandler();
private:
static constexpr uint32_t maxMessages_ = 10000;
std::queue<UnqPtr<Message>, std::vector<UnqPtr<Message>>> msqQueue_;
};
message_handler.cpp
#include "trpch.h" //precompiled header
#include "message_handler.h"
MessageHandler::MessageHandler()
{
//reserve space in the underlying vector
std::vector<UnqPtr<Message>> queue;
queue.reserve(maxMessages_);
msqQueue_ = std::queue{queue};
}

Fatal error when compiling #include <sys/uio.h> on project [windows]

trying to compile a file for class, using the mingw compiler on windows 10. Compiling with g++ gives me an error stating
\projectFile.o
mingw32-g++.exe -o D:\GitHub\GitRepo\projectFile.exe D:\GitHub\GitRepo\projectFile.o
D:\GitRepo\projectFile.cpp:16:20: fatal error: sys/uio.h: No such file or directory
compilation terminated.
From what ive read this header file
#include <sys/uio.h>
is a unix header and is generally included with most unix build environments. I am working on Windows 10 build and have been unsuccessful in trying to get this to work. Is there a work around for windows using different headers? Is there a while to install this file somehow?
The project is a generalized XML parser that as a student my job is to extract functions from the main file so that they can be reused (OOP design space)
#include <iostream>
#include <iterator>
#include <string>
#include <cstring>
#include <sys/types.h>
#include <sys/io.h>
#include <unistd.h>
#include <errno.h>
#include <vector>
#include <algorithm>
#include <ctype.h>
#include "XMLParser.hpp"
Built on Windows 10 (lastest build) with Mingw-64 (lastest version)
This will not compile for me
This fixed my problem creating this uio.h file in sys directory of mingw64
#ifndef SYS_UIO_H
#define SYS_UIO_H
#include <inttypes.h>
#include <unistd.h>
struct iovec
{
void *iov_base; /* Base address of a memory region for input or output */
size_t iov_len; /* The size of the memory pointed to by iov_base */
};
ssize_t readv(int fildes, const struct iovec *iov, int iovcnt);
ssize_t writev(int fildes, const struct iovec *iov, int iovcnt);
#endif /* SYS_UIO_H */

undefined reference to `std::__default_alloc_template<true, 0>::deallocate(void*, unsigned int)'

During linking code on ubuntu I get following error
undefined reference to 'std::__default_alloc_template<true, 0>::deallocate(void*, unsigned int)'
I tried several g++ compilers but nothing changes. The reason I found in previous answers is wrong configuration if includes. Here are includes in the code:
#pragma warning(disable:4786)
#include <stdio.h>
#include <map>
#include <string>
#include <vector>
#include <png.h>
#include <math.h>
#include <ft2build.h>
#include <gd.h>
#include FT_FREETYPE_H
using namespace std;
#ifndef WIN32
#define stricmp strcasecmp
#else
#include <io.h>
#include <fcntl.h>
#endif
Please help to fix those includes?
Your are probably compiling and linking with gcc instead of g++. For compilation, there's not much difference. GCC uses the file extension to guess the real language, but when linking, g++also pulls in the C++ Standard library, which is where allocators are usually defined.

Why use precompiled headers (C/C++)?

Why use precompiled headers?
Reading the responses, I suspect what I've been doing with them is kind of stupid:
#pragma once
// Defines used for production versions
#ifndef PRODUCTION
#define eMsg(x) (x) // Show error messages
#define eAsciiMsg(x) (x)
#else
#define eMsg(x) (L"") // Don't show error messages
#define eAsciiMsg(x) ("")
#endif // PRODUCTION
#include "targetver.h"
#include "version.h"
// Enable "unsafe", but much faster string functions
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
// Standard includes
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <direct.h>
#include <cstring>
#ifdef _DEBUG
#include <cstdlib>
#endif
// Standard Template Library
#include <bitset>
#include <vector>
#include <list>
#include <algorithm>
#include <iterator>
#include <string>
#include <numeric>
// Boost libraries
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/scoped_array.hpp>
//Windows includes
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "FILETIME_Comparisons.h"
#include <shlwapi.h>
#include <Shellapi.h>
#include <psapi.h>
#include <imagehlp.h>
#include <mscat.h>
#include <Softpub.h>
#include <sfc.h>
#pragma comment(lib, "wintrust.lib")
#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"Psapi.lib")
#pragma comment(lib,"shlwapi.lib")
#pragma comment(lib,"imagehlp.lib")
#pragma comment(lib,"Advapi32.lib")
#pragma comment(lib,"Shell32.lib")
#pragma comment(lib,"Sfc.lib")
#pragma comment(lib,"Version.lib")
// Crypto ++ libraries
#ifdef _DEBUG
#pragma comment(lib,"cryptlibd.lib")
#else
#pragma comment(lib,"cryptlib.lib")
#endif
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
#include <md5.h>
#include <sha.h>
// String libraries
#include "stringUnicodeConversions.h"
#include "expandEnvStrings.h"
#include "randomString.h"
#include "getShortPathName.h"
// Regular Expression Libraries
#include "fpattern.h"
// File Result Record
#include "unixTimeToFileTime.h"
#include "fileData.h"
// Writer
#include "writeFileData.h"
// Criteria Structure System
#include "priorities.h"
#include "criterion.H"
#include "OPSTRUCT.H"
#include "regexClass.H"
#include "FILTER.h"
// Sub Programs Root Class
#include "subProgramClass.h"
// Global data
#include "globalOptions.h"
// Logger
#include "logger.h"
// Console parser
#include "consoleParser.h"
// Timeout handler
#include "timeoutThread.h"
// Zip library
#include "zip.h"
#include "unzip.h"
#include "zipIt.h"
// Scanner
#include "mainScanner.h"
#include "filesScanner.h"
// Sub Programs
#include "volumeEnumerate.h"
#include "clsidCompressor.h"
#include "times.h"
#include "exec.h"
#include "uZip.h"
// 64 bit support
#include "disable64.h"
In C/C++, the #include mechanism is a textual copy of the file specified into the current file. Headers include other headers (which include yet other headers), so when you do a #include, it could be adding tens of thousands of lines of C++ into each cpp file (or cxx, c, whatever), all of which need to be compiled each time. This can be a severe bottleneck for large projects.
Precompiled headers speed this up by compiling each header once, then including that compiled state into the cpp they are included in.
It compiles a lot quicker. C++ compilation takes years without them. Try comparing some time in a large project!
Re: your current usage, if you have a target with a very large number of files, it may still be faster to use PCH in that way - try switching them off to find out. It depends: if you have a lot of headers of your own, and you change them only infrequently, and you have a very large number of source files that you change much more frequently, then your PCH usage will cut rebuild times.
But normal advice is to only put things in PCH that never change, because there is a certain overhead to producing the PCH itself. If you trigger that off with every rebuild (by constantly tweaking one of your headers), using PCH may make the rebuild slower.
So you don't have to compile them every time you build your project. They're used for system headers that aren't going to change.
It speeds up compilation.
When you're including headers from other projects, you don't expect to change them. If you put these into a precompiled header, then that code will not have to be recompiled when you make changes to your source code. This reduces repetitive compilation of unchanged code, speeding up compile time.