How to include readline into a Zig project - c

I am trying to use readline in my Zig project.
I managed to make the linker find it by adding this to the build file:
exe.linkLibC();
exe.addIncludeDir("/usr/local/opt/readline/include");
exe.addLibPath("/usr/local/opt/readline/lib");
Even though it finds readline definitions it seems it doesn't "see" the C lib...
Error:
▶ zig build
./src/main.zig:1:18: error: C import failed
const readline = #cImport({
^
/usr/local/opt/readline/include/readline/rltypedefs.h:71:36: note: unknown type name 'FILE'
typedef int rl_getc_func_t PARAMS((FILE *));
^
/usr/local/opt/readline/include/readline/readline.h:448:28: note: unknown type name 'FILE'
extern int rl_getc PARAMS((FILE *));
^
/usr/local/opt/readline/include/readline/readline.h:578:8: note: unknown type name 'FILE'
extern FILE *rl_instream;
^
/usr/local/opt/readline/include/readline/readline.h:579:8: note: unknown type name 'FILE'
extern FILE *rl_outstream;
^
/usr/local/opt/readline/include/readline/readline.h:937:3: note: unknown type name 'FILE'
FILE *inf;
^
/usr/local/opt/readline/include/readline/readline.h:938:3: note: unknown type name 'FILE'
FILE *outf;
^
zig-lua...The following command exited with error code 1:
How can I make it work?

It seems that the problem was not in the build file but in the cImport.
I was doing this:
const readline = #cImport({
#cInclude("readline/readline.h");
});
As the error message was complaining about stuff from C's stdio.h, I added that too:
const readline = #cImport({
#cInclude("stdio.h");
#cInclude("readline/readline.h");
});
And now the Zig build works.

Related

vulkan_win32.h is not "recognized"

I'm following this Vulkan tutorial: https://youtu.be/dHPuU-DJoBM, in particular, this video https://youtu.be/6Kj3O2Ov1RU
when I run in VS code, this errors shows (there are a lot of them, but all of the same type), i think is something with Windows implementation(?): log of VS code terminal:
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:30:5: error: unknown type name 'HINSTANCE'
HINSTANCE hinstance;
^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:31:5: error: unknown type name 'HWND'
HWND hwnd;
^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:57:5: error: unknown type name 'HANDLE'
HANDLE handle;
^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:58:5: error: unknown type name 'LPCWSTR'
LPCWSTR name;
^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:64:11: error: unknown type name 'SECURITY_ATTRIBUTES'
const SECURITY_ATTRIBUTES* pAttributes;
^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:65:5: error: unknown type name 'DWORD'
DWORD dwAccess;
^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:66:5: error: unknown type name 'LPCWSTR'
LPCWSTR name;
^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:82:136: error: unknown type name 'HANDLE'
...*PFN_vkGetMemoryWin32HandleKHR)(VkDevice device, const VkMemoryGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* ... ^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:83:135: error: unknown type name 'HANDLE'
...*PFN_vkGetMemoryWin32HandlePropertiesKHR)(VkDevice device, VkExternalMemoryHandleTypeFlagBits handleType, HANDLE ha... ^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:89:5: error: unknown type name 'HANDLE'
HANDLE* pHandle);
^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:94:5: error: unknown type name 'HANDLE'
HANDLE handle,
^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:125:5: error: unknown type name 'HANDLE'
HANDLE handle;
^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:126:5: error: unknown type name 'LPCWSTR'
LPCWSTR name;
^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:132:11: error: unknown type name 'SECURITY_ATTRIBUTES'
const SECURITY_ATTRIBUTES* pAttributes;
^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:133:5: error: unknown type name 'DWORD'
DWORD dwAccess;
^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:134:5: error: unknown type name 'LPCWSTR'
LPCWSTR name;
^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:154:142: error: unknown type name 'HANDLE'
...device, const VkSemaphoreGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle);
^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:164:5: error: unknown type name 'HANDLE'
HANDLE* pHandle);
^
C:\VulkanSDK\1.3.239.0/Include\vulkan/vulkan_win32.h:177:5: error: unknown type name 'HANDLE'
HANDLE handle;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
Error:1
this is what is shown if I run vulkaninfo:
WARNING: [Loader Message] Code 0 : loaderAddLayerProperties: C:\VulkanSDK\1.3.239.0\Bin\VkLayer_api_dump.json invalid layer manifest file version 1.2.0. May cause errors.
WARNING: [Loader Message] Code 0 : loaderAddLayerProperties: C:\VulkanSDK\1.3.239.0\Bin\VkLayer_gfxreconstruct.json invalid layer manifest file version 1.2.0. May cause errors.
WARNING: [Loader Message] Code 0 : loaderAddLayerProperties: C:\VulkanSDK\1.3.239.0\Bin\VkLayer_khronos_synchronization2.json invalid layer manifest file version 1.2.0. May cause errors.
WARNING: [Loader Message] Code 0 : loaderAddLayerProperties: C:\VulkanSDK\1.3.239.0\Bin\VkLayer_khronos_validation.json invalid layer manifest file version 1.2.0. May cause errors.
WARNING: [Loader Message] Code 0 : loaderAddLayerProperties: C:\VulkanSDK\1.3.239.0\Bin\VkLayer_screenshot.json invalid layer manifest file version 1.2.0. May cause errors.
WARNING: [Loader Message] Code 0 : loaderAddLayerProperties: C:\VulkanSDK\1.3.239.0\Bin\VkLayer_khronos_profiles.json invalid layer manifest file version 1.2.1. May cause errors.
this is my Vulkan config:
Vulkan Instance Version: 1.2.162
Instance Extensions: count = 11
===============================
VK_EXT_debug_report : extension revision 9
VK_EXT_debug_utils : extension revision 2
VK_EXT_swapchain_colorspace : extension revision 4
VK_KHR_device_group_creation : extension revision 1
VK_KHR_external_fence_capabilities : extension revision 1
VK_KHR_external_memory_capabilities : extension revision 1
VK_KHR_external_semaphore_capabilities : extension revision 1
VK_KHR_get_physical_device_properties2 : extension revision 2
VK_KHR_get_surface_capabilities2 : extension revision 1
VK_KHR_surface : extension revision 25
VK_KHR_win32_surface : extension revision 6
I've tried to follow this (How to make VK_LAYER_KHRONOS_validation available?) but Windows doesn't let me delete the register
I installed the latest Vulkan SDK so it doesn't seem to be the problem. Can someone help me?

unknown type name while compiling C program

I am newbie to C program and I use Linux odroid 4.9.277-122 aarch64 GNU/Linux. I compiled the C program using make PLATFORM=gcc-linux-arm BUILD=release
In my main.C it use twMessages, twMessaging, twApi header files and I got the following error.
May I know why it gives unknown type name in the header file and how can I solve the issue?
Is it related to the platform= gcc-linux-arm that I used while compiling?
In file included from ../src/twMessages.h:13,
from ../src/twMessaging.h:7,
from ../src/twApi.h:21,
from ../src/main.c:99:
../src/twInfoTable.h:88:2: error: unknown type name 'twList'
88 | twList * aspects; /**< A ::twList of the aspects associated with the entry. **/
| ^~~~~~
../src/twMessages.h:68:2: error: unknown type name 'twList'
68 | twList * headers;
| ^~~~~~
../src/twApi.h:166:2: error: unknown type name 'twList'
166 | twList * bindEventCallbackList; /**< Pointer to a ::twList of bind event callbacks. **/
| ^~~~~~
In file included from ../src/main.c:99:
../src/twApi.h:30:22: error: unknown type name 'twList'; use 'struct' keyword to refer to the type
30 | #define propertyList twList /* A propertyList is a twList */

Document Classification tool in C - Compilation error in nested function/scope (may be)

https://stackoverflow.com/questions/43423803/document-classification-tool-in-c-compilation-error/43432470#43432470
In above link-
I get 3 errors after adding -fnested_functions as
gcc -c ./rainbow.c -fnested-functions process_wv.c test_file.c test_hdb_file.c
(The 3 files process_wv, test_file, test_hdb_file are removed from rainbow.c and added as seperate .c files to the directory now)
Output:-
./bow/libbow.h:1345:8: note: forward declaration of 'struct argp_child'
struct argp_child; /* forward declare this type */
^
./rainbow.c:655:5: error: function definition is not allowed here
{
^
./rainbow.c:663:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
#endif VPC_ONLY
^
//
./rainbow.c:734:3: warning: implicit declaration of function 'do_indexing' is invalid in C99
[-Wimplicit-function-declaration]
do_indexing ();
^
./rainbow.c:1175:49: warning: passing 'int *' to parameter of type 'socklen_t *' (aka 'unsigned int *') converts between
pointers to integer types with different sign [-Wpointer-sign]
newsockfd = accept(rainbow_sockfd, &cli_addr, &clilen);
^~~~~~~
/usr/include/sys/socket.h:681:69: note: passing argument to parameter here
int accept(int, struct sockaddr * __restrict, socklen_t * __restrict)
^
./rainbow.c:1586:30: error: use of undeclared identifier 'test_file'
bow_map_filenames_from_dir (test_file.c, 0, dir, "");
^
P.S Why is test_file.c unidentified (bow_map_filenames_from_dir in docnames.c) in rainbow.c even though they are inside the same bow-20020213 folder (Permissions are 755 for all)
Regards
taking this .. as a starting point:
./bow/libbow.h:1345:8: note: forward declaration of 'struct argp_child'
struct argp_child; /* forward declare this type */
The linked code has a major problem in not including all the header files (in any specific header file) that that specific header file needs.
BTW: the 'struct argp_child' is defined in the ./argp/argp.h header file.
I did the following:
downloaded all the files via the .zip facility
expanded the .zip file to ~/src_bow on my ubuntu linux computer
cd ~/src_bow
./configure
edited the resulting 'Makefile' to define the macro:
CFLAGS = -g -O -Wall -Wextra -std=gnu11 -Wimplicit
then entered:
make -f Makefile
The result was hundreds of warnings, notes and errors
Most of the compiler output messages were about syntax, incomplete struct definitions, ignored modifiers and conversions However, there were many many other problems exposed.
After fixing a couple of hundred of the problems I stopped.
To answer your question, the root of the problems you are having has to do with the appropriate header files not being included in other header files that need the information in the header files that are not being included in each header file.

Issue to compile protobuf-c on MIPS target system

This is cross compile issue.
I crated xxxx.proto and generated C code by using protobuf-c project. It was compiled successfully on x86 linux.
But when I cross compiled it for MIPS, then it made compile error. I compiled protobuf, protobuf-c by using buildroot. And toolchain is sorcery tools.
The source code is like below.
#include <string.h>
#include "egmessage.pb-c.h" //header file that protobuf-c generated. I never touched it.
int main (void)
{
printf("Hello, world.");
return 0;
}
I tried to compile this code by using command below.
mips-linux-gnu-gcc egmessage.pb-c.c test.c -o extest -I/home/vagrant/tools/buildroot-2014.11/output/staging/usr/include -lprotobuf-c
Then I got the compile error like below.
In file included from test.c:6:0:
egmessage.pb-c.h:20:1: error: expected '=', ',', ';', 'asm' or '__attribute__' b
efore 'typedef'
typedef struct _ControlMessage ControlMessage;
^
egmessage.pb-c.h:35:23: error: unknown type name 'ControlMessage'
(ControlMessage *message);
^
egmessage.pb-c.h:37:22: error: unknown type name 'ControlMessage'
(const ControlMessage *message);
^
egmessage.pb-c.h:39:22: error: unknown type name 'ControlMessage'
(const ControlMessage *message,
^
egmessage.pb-c.h:42:22: error: unknown type name 'ControlMessage'
(const ControlMessage *message,
^
egmessage.pb-c.h:44:1: error: unknown type name 'ControlMessage'
ControlMessage *
^
egmessage.pb-c.h:50:23: error: unknown type name 'ControlMessage'
(ControlMessage *message,
^
egmessage.pb-c.h:54:18: error: unknown type name 'ControlMessage'
(const ControlMessage *message,
^
test.c:8:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
int main (void)
^
Error message said it want to use several symbol. Have you the experience like that?
I found the reason. I used protobuf I compiled manually. That version is different from buildroot's protobuf version. I applied buildroot's protobuf and compiled proto file again. Then it worked.

Eclipse goto label not working in C

I am using the Eclipse CDT and I have a goto label and a FILE definition after it and when I compile the project it gives me the error: Expression expected before FILE.
Thanks in advance,
Mr. Man
EDIT:
Ok, so this is what I get from the command line:
iOS.c: In function ‘main’:
iOS.c:45: error: expected expression before ‘FILE’
iOS.c:49: error: ‘preFile’ undeclared (first use in this function)
iOS.c:49: error: (Each undeclared identifier is reported only once
iOS.c:49: error: for each function it appears in.)`
And this is what code throws the error:
fileExists:
FILE *preFile = fopen("prefix.txt","r");
As you're coding in C, you need to declare the variable at the beginning of the function:
void foo()
{
FILE* preFile;
// some code
fileExists:
preFile = fopen("prefix.txt","r");
}

Resources