Executing legacy opengl code in codeblocks - c

I have an old program that uses legacy opengl. I am attempting to run the code, but I have been stumbling into some errors. I installed freeglut and attempted to link it and add the includes, and while it seems to execute, I get an error in the process that states:
undefined reference to `_imp___glutInitWinExit#12
The bit of code in the freeglut_std.h header file that is causing the error is located at:
static void FGAPIENTRY FGUNUSED glutInit_ATEXIT_HACK(int *argcp, char **argv_ { _glutInitWithExit(argcp, argv, exit); }
This is line 637 of the code, so I presume I linked freeglut properly, but for some reason is stopping just short of execution. I am not sure what steps I should take from here, and any help is appreciated. Thank you.
Edit: Build log (a snippet of it) -
C:/Program Files (x86)/CodeBlocks/MinGW/include/GL/freeglut_std.h:637: undefined reference to `_imp____glutInitWithExit#12'
obj\Debug\curve.o: In function `glutCreateWindow_ATEXIT_HACK':
C:/Program Files (x86)/CodeBlocks/MinGW/include/GL/freeglut_std.h:639: undefined reference to `_imp____glutCreateWindowWithExit#8'
obj\Debug\curve.o: In function `glutCreateMenu_ATEXIT_HACK':
C:/Program Files (x86)/CodeBlocks/MinGW/include/GL/freeglut_std.h:641: undefined reference to `_imp____glutCreateMenuWithExit#8'
obj\Debug\curve.o: In function `curve_buildLine':

Related

How to add .lib files in C static linking? (undefined reference to error)

I am trying a sample IXChariot API. These are the requirements before compiling and running the C file.
IX Chariot C API requiements. I have added both the include files and the lib files in the source directory I am working on, as said in the changes.
I have tried to add these path to environment variables as said in the API. But when during compilation of the main.c file, I am getting a undefined reference to error.
Error Received during compilation:- undefined reference to `CHR_api_initialize'
collect2.exe: error: ld returned 1 exit status
The CHR_api_initialize is already defined in the header file(chrapi.h), but I am getting an undefined reference error. I am not much familiar with C as I am with other languages.
The code and file structure is in this reddit link as Stackoverflow does not allow me to upload my code eventhough it is formatted. Link for file structure and code
Can anyone help me on this and point out what needs to be corrected?

Setting up the `regex.h` library on Windows with VS Code

I've been trying to get the regex.h library to work all day, but it's not working. (Here are my VS Code workspace configurations: https://github.com/EnderCommunity/Murmur/tree/main/.vscode - all the compiler info are here)
This is the file that I was trying to get the regex library to work with:
https://github.com/EnderCommunity/Murmur/blob/main/compiler/libraries/regex/reg.h
I tried to include the library normally, but it returns an error:
And I tried to include this library, but it returns some compiling errors:
> Executing task: C/C++: gcc.exe build active file <
Starting build...
"C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\gcc.exe" -g C:\Users\adels\Desktop\EnderCommunity\Projects\Murmur\compiler\start.c -o C:\Users\adels\Desktop\EnderCommunity\Projects\Murmur\compiler\start.exe
C:\Users\adels\AppData\Local\Temp\ccifSq1r.o: In function `regChk':
C:/Users/adels/Desktop/EnderCommunity/Projects/Murmur/compiler/libraries/regex/reg.h:15: undefined reference to `__imp_regcomp'
C:/Users/adels/Desktop/EnderCommunity/Projects/Murmur/compiler/libraries/regex/reg.h:22: undefined reference to `__imp_regexec'
C:/Users/adels/Desktop/EnderCommunity/Projects/Murmur/compiler/libraries/regex/reg.h:33: undefined reference to `__imp_regerror'
C:/Users/adels/Desktop/EnderCommunity/Projects/Murmur/compiler/libraries/regex/reg.h:40: undefined reference to `__imp_regfree'
collect2.exe: error: ld returned 1 exit status
Build finished with error(s).
The terminal process terminated with exit code: -1.
Terminal will be reused by tasks, press any key to close it.
So the way that I included this library might be wrong! What am I doing wrong here?
Using MSYS2 will fix this, it comes with all the necessary libraries for C.

undefined reference to `vec_expand_'

I've come across rxi/vec library for dynamic array implementation for C on GitHub.
I'm trying to run the sample program that is given in the README's usage section.
I've implemented the code like this
#include <stdio.h>
#include "vec.h"
int main()
{
vec_int_t v;
vec_init(&v);
vec_push(&v, 123);
vec_push(&v, 456);
printf("%d\n", v.data[1]); /* Prints the value at index 1 */
printf("%d\n", v.length); /* Prints the length of the vector */
vec_deinit(&v);
return 0;
}
But everytime I'm runnung the program it is throwing this error in the VS Code's terminal:
> Executing task: C/C++: gcc.exe build active file <
Starting build...
Build finished with errors(s):
C:\Users\user\AppData\Local\Temp\cctdgiKc.o: In function `main':
D:/Test.c:9: undefined reference to `vec_expand_'
D:/Test.c:10: undefined reference to `vec_expand_'
collect2.exe: error: ld returned 1 exit status
The terminal process failed to launch (exit code: -1).
On Visual Studio, the error looks something like this...
Visual Studio Error Screenshot
The error appears to be from these two lines:
vec_push(&v, 123);
vec_push(&v, 456);
Also I have tried c-vector library and code from this answer but these are giving same kind of error .
I'm new to C programming so I'm not able to understand what's going on here and it's possible that I might be doing some silly mistake.
Thank you in advance.
You have failed to link the library with your program.
Doing
#include "vec.h"
does nothing to being the actual code in, all it does is to paste in the text of the header (with declarations) at the point of the #include.
The exception is "header only" libraries, but it seems that library is not a header only implementation. The vec_init() function seems to be a macro (or an inline function) since you're not getting errors for it.
You must tell your linker to add the code from the library in question when creating your executable.
How this is done is compiler-specific.

fatal error: sodium.h: No such file or directory

Thank you #stark I was unaware you had to link the directory as part of #include. This part is now working though when I include.
(sodium_init() < 0)
{
printf("Sodium could not be initialized");
return 1;
}
I now receive the error "undefined reference to 'sodium_init'.
I have tried adding -lsodium to the compile command (gcc -g -lsodium file1.c file2.c file1.h -o file1.c.exe) which gives the error.
"cannot find -lsodium collect2.exe: error: ld returned 1 exit status"
Through further searching I believe I need to tell the compiler where to find -lsodium though cannot find out how.
-- below has been solved using #stark advice --
I have been trying to get the sodium library working for the last 3 days. I have followed the instillation instructions here(https://libsodium.gitbook.io/doc/installation) which all appear to have completed successfully, but still receive the error.
I then found information suggesting I have not linked Visual Studio (community edition) to the library location.
I have attempted to follow the instructions here(https://www.learncpp.com/cpp-tutorial/a2-using-libraries-with-visual-studio-2005-express/) but cannot see "VC++ Directories". I have tried several other sets of directions with the same outcome.
Is anyone able to help getting the sodium library working so I can get access to the RtlGenRandom() function?

Microchip problem with usb_device.c file, getting errors i cannot solve

Well the problem is these errors
I have not touched these files but just downloaded the legacy mla and used the files. So I'm assuming there is a problem with my directories in some way.
I have the path to the microchip/include file and some of the code works. So now when im building the project i encounter these problems. I've tried changing the paths, using linker folders but nothing seems to work.
I know the the functions are in the usb_device_local.h file and its included but still nothing
im using mplabx v5.15, and xc32 compiler v2.15. Also a older pic32mx
build/default/production/_ext/2021492214/usb_device.o: In function `_USB1Interrupt':
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:887: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:937: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:995: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
build/default/production/_ext/2021492214/usb_device.o: In function `USBStdSetCfgHandler':
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2180: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
build/default/production/_ext/2021492214/usb_device.o: In function `USBStdGetDscHandler':
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2218: undefined reference to `device_dsc'
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2218: undefined reference to `device_dsc'
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2226: undefined reference to `USB_CD_Ptr'
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2226: undefined reference to `USB_CD_Ptr'
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2242: undefined reference to `USB_SD_Ptr'
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2242: undefined reference to `USB_SD_Ptr'
build/default/production/_ext/2021492214/usb_device.o: In function `USBSuspend':
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2437: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
build/default/production/_ext/2021492214/usb_device.o: In function `USBWakeFromSuspend':
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2463: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
build/default/production/_ext/2021492214/usb_device.o: In function `USBCtrlTrfSetupHandler':
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2657: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
build/default/production/_ext/2021492214/usb_device.o: In function `USBCheckStdRequest':
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2879: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
build/default/production/_ext/2021492214/usb_device.o: In function `USBStdFeatureReqHandler':
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:3041: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
build/default/production/_ext/2021492214/usb_device.o:c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:3071: more undefined references to `USER_USB_CALLBACK_EVENT_HANDLER' follow
collect2.exe: error: ld returned 255 exit status
Looking at the compiler you are using and the date that this tutorial was made leads me to believe that the some of the tutorial is not only out of date but the the main/interrupt code will be incompatible with the type of PIC and compiler you are using. (So even if you could get rid of these errors you'd just get more unless you know what you are doing!)
However, if you have followed the tutorial correctly and added the HardwareProfile.h, usb_device.c, usb_descriptors.c and main.c files from the tutorial (except the interrupt and #config stuff in main.c as they will be incompatible with the PIC32), it should build successfully albeit with a bunch of unrelated PLIB warnings.
The file structure should be like this below:
usb_descriptors.c, main.c, HardwareProfile.h, usb_config.h should all be your own created .c files via New --> C Source File to your project and adding the code from the tutorial. These should then exist in your project folder.
Whereas usb_device.c and usb_function_cdc.c should be from the microchip mla folder
As the tutorial states, albeit not very clearly, you must set the include directories correctly.
To do this go to Project Options then:
xc32 (Global Options) --> Common include dirs
set the following:
(Whereever MLA is installed , mine is probably a different version)
And do the same for
xc32-as General --> Preprocessor Include directories and
xc32-as General --> Assembler Include directories
Microchip recommends on their website 32-bit PIC32 customers (except for PIC32MM) should use MPLAB Harmony Integrated Software Framework which includes TCPIP, USB, Graphics, File systems and more. If you are using PICMM then I'd recommend the latest version of MLA, not 2013 version, you can find on the Microchip MLA page. If not I'd recommend learning their harmony plugin.

Resources