How do i compile a glib application in windows withnout pkg-config? - c

I am trying to compile a glib application in windows 10, but i keep getting this error:
In file included from C:\Users\DamŔa\Desktop\C\glib-2.0/glibconfig.h:9,
from C:\Users\DamŔa\Desktop\C\glib-2.0/glib/gtypes.h:32,
from C:\Users\DamŔa\Desktop\C\glib-2.0/glib/galloca.h:32,
from C:\Users\DamŔa\Desktop\C\glib-2.0/glib.h:30,
from main.c:3:
C:\Users\DamŔa\Desktop\C\glib-2.0/glib/gtypes.h: In function '_GLIB_CHECKED_ADD_U64':
C:\Users\DamŔa\Desktop\C\glib-2.0/glib/gmacros.h:818:31: error: static assertion failed: "Expression evaluates to false"
#define G_STATIC_ASSERT(expr) _Static_assert (expr, "Expression evaluates to false")
^~~~~~~~~~~~~~
C:\Users\DamŔa\Desktop\C\glib-2.0/glib/gmacros.h:818:31: note: in definition of macro 'G_STATIC_ASSERT'
#define G_STATIC_ASSERT(expr) _Static_assert (expr, "Expression evaluates to false")
while trying to compile it with this command:
gcc -I"C:\Users\Damča\Desktop\C\glib-2.0" main.c
I did some research and found out that it could be because i am not using pkg-config, but it doesn't work on windows, because it cant find the file glib-2.0.pc.
so, how can i compile it withnout pkg-config? or how do i make it work on windows?

The GLib source code for Linux won't work for Windows. Use the Windows version and try again. Set the environment variable PKG_CONFIG_PATH to the .pc file

Related

PDCurses wont compile on windows

I am trying to compile PDCurses, but when it attempts to compile pdcscrn.c it gives the error message
../wincon/pdcscrn.c:93:5: error: unknown type name 'PCONSOLE_SCREEN_BUFFER_INFOEX'; did you mean 'PCONSOLE_SCREEN_BUFFER_INFO'?
PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PCONSOLE_SCREEN_BUFFER_INFO
../wincon/pdcscrn.c:95:5: error: unknown type name 'PCONSOLE_SCREEN_BUFFER_INFOEX'; did you mean 'PCONSOLE_SCREEN_BUFFER_INFO'?
PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PCONSOLE_SCREEN_BUFFER_INFO
../wincon/pdcscrn.c:97:8: error: unknown type name 'SetConsoleScreenBufferInfoExFn'
static SetConsoleScreenBufferInfoExFn pSetConsoleScreenBufferInfoEx = NULL;
and there are also a lot more lines, but that is the first part. I am using GCC 8.2.0, and I compiling the wincon directory because I am on windows 10. Thanks.
This is addressed in wincon/README.md:
If your build stops with errors about PCONSOLE_SCREEN_BUFFER_INFOEX,
add the parameter "INFOEX=N" to your make command line and try again.
(This will happen with older compile environments.)
BTW, you should specify the exact toolset you're using, since AFAIK there's no such thing as raw GCC for Windows -- it'll be something like MinGW or Cygwin.

Preprocessor: error: missing binary operator before token "("

we're curruntly working on a C project and we've downloaded and used the header dirent.h, the problem is the code was compiled successfully on my teammate laptop but in mine it doesn't compile, telling me this :
In file included from utils.c:6:0:
dirent.h: In function '_wopendir':
dirent.h:383:28: error: missing binary operator before token "("
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
^
dirent.h:405:28: error: missing binary operator before token "("
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
^
dirent.h:413:5: warning: implicit declaration of function 'wcsncpy_s' [-Wimplicit-function-declaration]
wcsncpy_s (dirp->patt, n+1, dirname, n);
^
I searched for the problem and find that it's a preproccessor error and currently on the #if
i've tried to add #define WINAPI_FAMILY_PARTITION(Partitions) but it doesn't work.
Please suggest me a solution to compile it successfully, and does the windows version affect on preprocessing?
WINAPI_FAMILY_PARTITION is defined in <winapifamily.h>, probably included by <windows.h>. Look at this question for more explanations, but windows intricacies are largely irrelevant for your compilation issue. You might want include <windows.h> before <dirent.h>?
You did not publish the source code for your program, nor did you specify what OS you compile for not what compiler you use, but you mention we've downloaded and used the header dirent.h... This sounds wrong: system include files such as <dirent.h> are automatically installed with the compiler, they are specific to the OS and compiler, you cannot just download one from the net and expect it to work on your system. It might work by chance on your teammate's PC because the OS might be different.

Failed to compile a simple c code with architecture not supported on mac os

The code is
#include <stdio.h>
int
main () {
printf("Defined\n");
}
And the simple code is compiled with
gcc test.c -o test
or
clang test.c -o test
It throws ...
In file included from test.c:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/usr/include/stdio.h:64:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/usr/include/_stdio.h:68:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/usr/include/sys/cdefs.h:784:2: error: Unsupported architecture
#error Unsupported architecture
^
In file included from test.c:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/usr/include/stdio.h:64:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/usr/include/_stdio.h:71:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/usr/include/_types.h:27:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/usr/include/sys/_types.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/usr/include/machine/_types.h:34:2: error: architecture not supported
#error architecture not supported
^
In file included from test.c:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/usr/include/stdio.h:64:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/usr/include/_stdio.h:71:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/usr/include/_types.h:27:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/usr/include/sys/_types.h:55:9: error: unknown type name '__int64_t'; did
you mean '__int128_t'?
typedef __int64_t __darwin_blkcnt_t; /* total blocks */
^
note: '__int128_t' declared here
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/usr/include/sys/_types.h:56:9: error: unknown type name '__int32_t'; did
you mean '__int128_t'?
typedef __int32_t __darwin_blksize_t; /* preferred block size */
^
note: '__int128_t' declared here
And more similar errors.
Of course the compiler properly works before, but after I updated mac os to 10.14.5 (18F132), it happens. Looks like there are some problems on compiler settings but I don't have any ideas where to start.
My clang version is
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Thanks #robthebloke,
I reinstalled everything related to xcode and it doesnt work. I rebooted the mac so that environmental variable are reset and it does work!
It looks like somehow I accidentally touched the environmental variables but I couldn't verify exactly which one is causing the problem.
FYI: I usually compile a bunch of c codes into several platforms: mac os, android, and ios. I guess my cross compile scripts have problem with the updated os or compiler(?).
And as #Clifford said, printenv | grep iPhoneOS might identify the problem.

off64_t in Cygwin

I have compiled program in minGW which I want to run in my computer which has Cygwin installed in my system. I have the following compilation error:
error: 'off64_t' undeclared (first use in this function)
I added the following to the CFLAGS in Makefile, but still having the same error.
-D"_LARGEFILE64_SOURCE" -D"_FILE_OFFSET_BITS=64"
Can someone suggest what am I missing here and what I need to add?
Cygwin does not define the off64_t type. Instead, if defines _off64_t. If you want to compile your existing code with minimal changes, add the following at the top of your sources:
#include <sys/types.h>
typedef _off64_t off64_t;

Getting an error for the features.h header, even though I haven't touched it?

I am running Linux Mint. When I try to compile a program in C using gpp from command line, I get this output, and my program does not compile.
$ gpp snake.cpp -o snake
features.h:384: warning: Extra argument to #endif ignored
features.h:396: error: #define/#defeval requires an identifier or a single macro call
I'm not sure why I would ever be getting an error for a standard library that I haven't even touched.

Resources