POSIX Headers (from MinGW project) in Visual Studi

2020-05-04 11:27发布

问题:

(Continues from: Porting from Code::Blocks to Visual Studio 2010 - I'll remove this if it's against StackExchange's formatting rules)

I'm trying to port an open source Code::Blocks project, which originally uses MinGW and GCC TDM-1 4.7.2 (does not support newer versions), to Visual Studio 2013 (NOTE: I switched from 2010 to 2013 for the question above). The code uses 1998 ISO C++ standard and uses various additional utilities like SDL2, OpenGL, Zlib, Lua, and others.

The main problem is, the project includes some libraries which VS does not have; so I wanted to ask if anybody knows if these are Unix-only libraries, libraries from a utility included in the project which I overlooked or libraries my VS installation is for whatever reason lacking, and mainly if they can be fixed, replaced with VS equivalents or downloaded from somewhere without massively porting/editing the code itself first.

In particular, at the current build attempt (I have not scanned through all of the project source files to look for other errors) the missing libraries are:

  • unistd.h(*)
  • cpuid.h
  • sys/time.h

(*)EDIT: I've looked a bit around and I found unistd.h can be possibly replaced with io.h or with a custom subset of the original Unix library, so I'll also try these options.


EDIT2: Apparently, they're all Unix (POSIX) libraries which, from what I understand, are fundamentally incompatible with the MSVC compiler, even if forcefully included into the project.

I've also tried to set the Visual Studio project to use MinGW as a custom compiler, but not only I can't get it to work properly, I've read that VS can not parse debug information from GCC-compiled binaries, which is one of the two major reasons I wanted to port to VS in the first place.

I've also read about this plugin called VisualGDB; does anybody know about it? Does it make possible for VS to compile and debug MinGW programs?

回答1:

Yeah, I tried the VisualGDB extension and it pretty much solves all the issues. MSVC and MinGW hate the crap out of each other and I really couldn't do much about it.



回答2:

I know this is an old post, but I had a similar problem with the time related headers. This was my solution.

This repository provided an implementation of those time related functions. They also appear to have an automatically exported github project with the same files, in case that original repository link stops working: https://github.com/zhouheng/madp-win/tree/master/src/include/sys

I took their three files: time.h, times.h and times.cpp, dropped them into a folder called "sys/" within my project directory, and then replaced all references to:

#include <sys/time.h>

to use:

#include "sys/time.h"

for local file reference. So far I have not encountered any problems. Please note this is not my code and the original license(s) of the code is LGPL.