Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

help in obtaining USB and NCurses

Hugh Aguilar

New Coder
Hello.
I want to write a terminal program to run under Windows.
I downloaded Code-Blocks and was able to compile and run a 'Hello World' program.
C:
#include <stdio.h>
int main() {
  printf("Hello, World!\n");
  return 0;
}

I don't know where STDIO.H is, but GCC seems to know because my PRINTF worked. Maybe there are libraries already there for USB and NCurses in which case I just need to include them.

I found LIBUSB-1.0.28.7Z and downloaded it, and ran 7Z to unzip it.
I got these two files out: LIBUSB-1.0.A and LIBUSB-1.0.DLL.A
I don't know what to do with .A files.

I also need to obtain documentation on how to use the code libraries for USB and NCurses as I've never used them before.

BTW: I downloaded CYGWIN but it put me into a BASH shell. I didn't know how to find my Windows directory. Also, it wasn't clear if I could write console programs that would run under PowerShell, so I ignored CYGWIN and tried Code Blocks that works out of PowerShell. I want to run out of PowerShell because I already have a terminal program written in Python that I'm using in PowerShell I didn't write the Python program. That program doesn't do what I want it to do, and I don't want to learn enough Python to upgrade it, which is why I'm writing my own program in C. I've not done any C programming in Windows, but I did some C programming in MS-DOS in the early 1990s (nothing to do with serial ports or NCurses though). I don't necessarily need an IDE like Code Blocks. In MS-DOS days I just wrote a MAKE file and never used any IDE.
 
Hey There and welcome 🙂

I see you're working on a Windows terminal program in C and have a few questions about libraries and compilation. Let me address these points:

The header file stdio.h is part of the C standard library that's automatically included with your compiler (GCC in Code::Blocks). That's why you don't need to find it manually.

For libusb:
  1. The .a file is a static library (archive). You'll need to link against it during compilation.
  2. The .dll is the dynamic library that your program will use at runtime.
To use these with Code::Blocks:
  • Add the header files directory to your include path
  • Add the library directory to your linker search path
  • Add libusb-1.0.a to your linked libraries
For ncurses on Windows, you'll want PDCurses instead - it's the Windows-compatible implementation. Download it from PDCurses

Documentation:
Here's a basic Makefile approach if you prefer not using an IDE:

makefile
Code:
CC = gcc
CFLAGS = -Wall -I/path/to/libusb/include -I/path/to/pdcurses/include
LDFLAGS = -L/path/to/libusb/lib -L/path/to/pdcurses/lib
LDLIBS = -lusb-1.0 -lpdcurses

program: program.c
    $(CC) $(CFLAGS) -o program program.c $(LDFLAGS) $(LDLIBS)

clean:
    rm -f program program.exe
Your Code::Blocks program will run fine in PowerShell. You just need to navigate to your executable and run it.
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom