I am using Windows 7-64 bit.
Borland C++ 5.5 isn't working.
Test file Hello.c
#include<stdio.h>
int main(void)
{
printf("Hello world!\n");
return 0;
}
Error E2209 Hello.c 1: Unable to open include file 'stdio.h'
Warning W8065 Hello.c 5: Call to function 'printf' with no prototype in function main
* 1 errors in Compile *
I have already made the bcc32.cfg & ilink.cfg with these configs
bcc32.cfg
-I"c:\Borland\BCC55\include"
-L"c:\Borland\BCC55\lib"
ilink32.cfg
-L"c:\Borland\BCC55\lib"
:confused:
First look for your include and library directory and see whether it is the same as in your borland C directories option
Related
I would like to use a library written in D for a C program compilable with MinGW GCC, for Windows. Here are the codes:
dll.d
extern (C) int dsquare(int n) nothrow
{
return n * n;
}
main.c
#include <stdio.h>
int main()
{
int res = dsquare(6); // Expect '36'
printf("res = %d\n", res);
return 0;
}
There is a tutorial on D's site, but it seems to target only Linux. Indeed, no explanation is given for creating such a dynamic D library for Windows and MinGW users.
D's documentation also says that the -shared option should generate a DLL version of the D code, but in my case, it generates an executable, I don't know why.
Also, anything that seems to generate files to be linked targets MVSC formats and nothing seems to be suitable for MinGW GCC compilers.
So, how can I generate a "GCC-friend" DLL with D, so that I can link it to my C program without having to use another compiler, such as GDC or LDC, via gcc main.c -o main -ldll -L. (I guess)?
I attached link with short explanation. Link D onto C is not so straightforward as C to D. Check D.org page here:
https://dlang.org/spec/betterc.html
I'm trying to get the ADC running on beaglebone black. The OS is Debian GNU/Linux 7.7. I'm using C language. When I try to compile the following code:
#include <stdio.h>
#include <unistd.h>
#include "pruio_c_wrapper.h"
#include "pruio_pins.h"
int main(int argc, const char *argv[]) {
PruIo *io = pruio_new(0, 0x98, 0, 1);
if (io->Errr) {
printf("Initialisation failed (%s)\n", io->Errr);
return 1;
}
if(pruio_config(io, 0, 0x1FE, 0, 4, 0)){
printf("Config failed (%s)\n", io->Errr);
return 1;
}
int a = 0;
int i;
while(1){
printf("\r%12o %12o %12o %12o %4X %4X %4X %4X %4X %4X %4X %4X\n", io->Gpio[0].Stat, io->Gpio[1].Stat, io->Gpio[2].Stat, io->Gpio[3].Stat, io->Value[1], io->Value[2], io->Value[3], io->Value[4], io->Value[5], io->Value[6], io->Value[7], io->Value[8]);
fflush(STDIN_FILENO);
usleep(1000);
}
pruio_destroy(io);
return 0;
}
But I get the following error:
undefined reference to 'pruio_new'
undefined reference to 'pruio_config'
I installed everything like FreeBasic compiler and pruss driver kit for freebasic and BBB and libpruio. I also copied all the header files in the same directory as the .c file, including "pruio_c_wrapper.h", "pruio-pins.h", "pruio.h" and all the other files in the src directory of libpruio. But it doesn't work.
Could you please tell me what to do?
Thanks
libfb is the FreeBASIC run-time library. When you want to compile against the old libpruio-0.0.x versions, you'll need an old FreeBASIC installation from
www{dot}freebasic-portal.de/dlfiles/452/bbb_fbc-0.0.2.tar.xz
Which installs /usr/local/lib/freebasic/libfb.so.
See the libpruio-0.0.x C example codes for compiler command line arguments (ie. header section of io_input.c).
But I recommend to use the new version libpruio-0.2 from (the last post links to the documentation of this new version)
http://www.freebasic-portal.de/dlfiles/592/libpruio-0.2.tar.bz2
which doesn't have this pitfalls, gcc compiles without FB installation, and provides new features like pinmuxing, PWM, CAP. There're small bugs in this versions C header, which is now named pruio.h: a missing enum and a copy / paste bug regarding a function name. See this thread for details:
http://www.freebasic.net/forum/viewtopic.php?f=14&t=22501
BR
Ok, I downloaded it, the binaries are in libpruio-0.0.2/libpruio/src/c_wrapper and so are the include files, copy the headers and libpruio.so to the same directory where the test.c file resides, and then
For the includes, you need to to append libpruio's include directory to the compiler command using -I. then you can do
#include <pruio_c_wrapper.h>
#include <pruio_pins.h>
You need to append the library to the linker command, with
-L. -lpruio
your complete compilation command will be then
gcc -o test -I. -L. -lpruio test.c
I am trying to find an implementation of the language in c that is actually based on the language standards ,here is a simple example
#include "linda.h"
int worker(int num)
{
int i;
for (i=0; i<num; i++)
out("hello, world");
return 0;
}
int main()
{
int result;
eval("worker", worker(5));
in("hello, world");
in("hello, world");
in("hello, world");
in("hello, world");
in("hello, world");
in("worker", ? result);
return 0;
}
So directly to your question:
Where can i find an implementation of the coordination language linda in c?
Here: http://www.comp.nus.edu.sg/~wongwf/linda.html
You can download it and use it!
If you download it you should get this:
linda //dir
|
| - linda.c //file
| - linda.h //file
| - primes.c //file
| - README.txt //file
But you have to know:
You must call linda_init() before you do linda stuff
You must call linda_end()before exiting
There is no eval() function but you can use spawn()
The library varargs.h is outdated! So i would recommend you to use: stdarg.h
So that means it could be that you have to rewrite stuff!
So there is only one thing todo!
Download it and get started!
EDIT:
Another way you could go is to download a Linda-C compiler and write your programs in Linda-C (*.clc).
So but back to library from above:
I got a program working with linda in c with this library!
I have: GNU GCC compiler(tdm64-1) 4.7.1 MinGW64
What you have to look out for:
In linda.h you have to change the include sys/varargs.h to stdarg.h since varargs is outdated!
That means also that you have to change in linda.c all va_arg() calls and change the following type:
float -> double
char -> int
After you have done that you should be able to compile linda.c to linda.o with this command line:
gcc -c -O linda.c (Also it could be that you have to direct to the gcc.exe so that the command gcc is known in Windows cmd)
So as an example:
Path to gcc compiler:
"C:\Program Files (x86)\Dev-Cpp\MinGW64\bin"
Path to linda library:
"C:\Users\xy\Downloads\linda\linda"
So now if you open cmd and type in: gcc --version and it's not found you have to direct to the gcc.exe file like this (otherwise your fine and you don't have to direct to the compiler dir):
cd "C:\Program Files (x86)\Dev-Cpp\MinGW64\bin"
So if your in the directory where gcc.exe is located you should be able to execute that command: gcc --version
And from there you can execute the command to create linda.o! Which looks like this in this example:
gcc -c -O C:\Users\xy\Downloads\linda\linda\linda.c
If all worked out! You should end up with the file linda.o in your compiler directory
And now with the file linda.o you can compile primes.c (Which is in this library as an example) and get a linda programm in c working! with the following line:
gcc -o C:\Users\xy\Downloads\linda\linda\primes -O C:\Users\xy\Downloads\linda\linda\primes.c C:\Users\xy\Downloads\linda\linda\linda.o -lpthread -lm
With this line you should end up with the .exe file: primes.exe! Which you can copy in the compiler directory and execute! If you don't have it in this dir then lpthreadGC2_64.dll is unknown and it can't be executed!
Few side notes to the compiling of this example:
lpthread -> pthread library
lm -> math library
Also i would recommend you to add the following line in the primes.c file at the end so that if you execute it, the window does not close instant: system("pause");
Also for your problem that with this library you can't use eval() there are a few workarounds/ solutions:
You can make a for loop and call your functions multiple times! (Since the function you call with spawn() has to have void as return type)
You can define a constant with: #define CALLS 5 and use this in the function itself for the commands to execute in a for loop or also in the main function to call spawn() multiple times
I think there are more ways to solve this!
So all that said. Your program should look something like this:
#include "linda.h"
#define NUM 5
void worker() {
int i;
for (i = 0; i < NUM; i++)
out("%s", "hello, world");
}
int main() {
int result;
spawn(worker);
in("%s", "hello, world");
in("%s", "hello, world");
in("%s", "hello, world");
in("%s", "hello, world");
in("%s", "hello, world");
in("%s?d", "worker", &result);
system("pause");
return 0;
}
Hope this helps you!
Cheers
I tried to write a simple D Program and use it to access a simple C library but there is unknown error.
My c Code, Box.c
#include "Box.h"
int SayHello( int _int)
{
_int ++;
return _int;
}
My c header file, Box.h
#ifndef BOX_H_INCLUDED
#define BOX_H_INCLUDED
/* export interfaces */
#ifdef __cplusplus
extern "C" {
#endif
int SayHello( int _int);
#ifdef __cplusplus
}
#endif
#endif // BOX_H_INCLUDED
I compile it
gcc -c Box.c Box.h
resulting files
Box.o
Box.h.gch
I place them to my D Program's project directory
My D Code
module main;
import std.stdio;
import std.conv;
import std.c.stdio;
import clib;
int main(string[] args)
{
// test external c library
auto s = to!string( SayHello(3) ) ;
writefln( "my int is "~ s );
readln();
return 0;
}
My D interface file ( clib ), trying to link to my C library
module clib;
import std.c.stdio;
extern (C) int SayHello( int _int);
The error I get when I compile it using codeblocks
Compiling: hello.d
Linking console executable: bin/Debug/tutorial03-access-c-library4
obj/Debug/hello.o: In function `_Dmain':
/home/hamilton/Tutorial/tutorial03-access-c-library4/hello.d:11: **undefined reference to `SayHello'**
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
Error is "undefined reference to `SayHello'"
There is no error I get when I compile it using command in console
$ dmd Box.o hello.d clib.di
it will be very painful if I cannot use codeblocks as I need the debugging functionality.
Thanks
Update:
Compiler setting in codeblocks as followed
Linker for dynamic libs: gcc -m32 -lrt
Linker for static libs: ar
Debugger: gdb
You can change the build options in CodeBlocks from Project -> Build Options, Compiler settings -> Other options. The simplest thing to do would be to just add Box.o to Other options.
I need to create an application to extract one file from zip archive, after which I want to compile it for Android.
I'm using Ubuntu, with libzip-0.10.1 pre-installed.
I created C project in Eclipse, added include path and found simple script for extracting file. Unfortunately I cannot get the following to build and I could use some advice.
// zip.c file
#include <stdio.h>
#include <stdlib.h>
#include <zip.h>
int main(int argc, char **argv) {
struct zip *zip_file;
struct zip_file *file_in_zip;
int err;
int files_total;
int file_number;
int r;
char buffer[10000];
if (argc < 3) {
fprintf(stderr,"usage: %s <zipfile> <fileindex>\n",argv[0]);
return -1;
};
zip_file = zip_open(argv[1], 0, &err);
if (!zip_file) {
fprintf(stderr,"Error: can't open file %s\n",argv[1]);
return -1;
};
file_number = atoi(argv[2]);
files_total = zip_get_num_files(zip_file);
if (file_number > files_total) {
printf("Error: we have only %d files in ZIP\n",files_total);
return -1;
};
file_in_zip = zip_fopen_index(zip_file, file_number, 0);
if (file_in_zip) {
while ( (r = zip_fread(file_in_zip, buffer, sizeof(buffer))) > 0) {
printf("%s",buffer);
};
zip_fclose(file_in_zip);
} else {
fprintf(stderr,"Error: can't open file %d in zip\n",file_number);
};
zip_close(zip_file);
return 0;
};
Also I added few .h files to include directory in my project and few .c files to directory with zip.c file. After that all dependences was good, but I have an error:
‘struct zip’ has no member named ‘default_password’ in file zip_fopen_index.c
The file zip_fopen_index.c is:
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "zipint.h"
ZIP_EXTERN struct zip_file *
zip_fopen_index(struct zip *za, zip_uint64_t fileno, int flags)
{
return zip_fopen_index_encrypted(za, fileno, flags, za->default_password); // error here
}
First of all allow me some comments:
Your program is not compiled and linked by Eclipse.
Compiling is done by the compiler (gcc using option -c):
make all
Building file: ../zip.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"zip.d" -MT"zip.d" -o "zip.o" "../zip.c"
Finished building: ../zip.c
Linking is done by the linker (via the compiler using option -o):
Invoking: GCC C Linker
gcc -o "unzipper" ./zip.o
./main.o: In function `zip':
/home/alk/workspace/unzipper/Debug/../zip.c:20: undefined reference to `zip_open'
/home/alk/workspace/unzipper/Debug/../zip.c:27: undefined reference to `zip_get_num_files'
/home/alk/workspace/unzipper/Debug/../zip.c:33: undefined reference to `zip_fopen_index'
/home/alk/workspace/unzipper/Debug/../zip.c:35: undefined reference to `zip_fread'
/home/alk/workspace/unzipper/Debug/../zip.c:38: undefined reference to `zip_fclose'
/home/alk/workspace/unzipper/Debug/../zip.c:43: undefined reference to `zip_close'
collect2: ld returned 1 exit status
Eclipse provides a framework helping you in managing all sources and their references as also spawing compiler and linker tasks and setting their options.
When the linker told you there where undefined references to the zip_*function during the build of your program, the cause for this was, you were missing to tell the linker (via the compiler, via Eclipse) where those zip_* functions could be found.
Those zip_* functions are located in a library, namely libzip.
So what you as the programmer need to tell the linker (via the compiler, via Eclipse) is to link those functions against what the compiler compiled from your sources.
As the result the linker is able to create a runnable program from your compiled sources together with all libraries needed. Certain libraries are know to Eclipse (and therfore to the linker) by default, for example the one containing the C standard functions, namely libc.
To get things going:
1 Remove the source files you pulled from the libzip librarie's sources from your project. Those sources had been compiled into the library libzip, which you will use in your project.
2 Tell the linker (via Eclipse) to use libzip for your project.
Do so by following the steps below:
open the project's properties
click 'C/C++ General'
click 'Path and Symbols', on the left select the 'Libraries' tab, there click 'Add' and enter zip
finally click 'OK'
3 Then try to build your program:
Building target: unzipper
Invoking: GCC C Linker
gcc -o "unzipper" ./zip.o -lzip
Finished building target: unzipper
(Please note additional option -lzip!)
If the developement version of 'libzip' had been installed properly before, you should be fine.
PS: unzipper was the name I used for the Eclispe project to produce the examples.
PSS: I used Eclipse Juno SR1