Failing to compile a 15+ year old MUD codebase written in C - c

I used this codebase to run a mud in the early 2000s, and through that, to teach myself some very elementary coding.
I just got a copy of the codebase from the administrator/coder who ran the server before me, and I'm just about certain that it would compile as-is back then, but now it won't.
My only guess is that it has something to do with updates to GCC in the last 15-20 years, but I'm admittedly a novice and pretty out of my depth here.
This is the error I get after about a hundred pages of warnings when I try to compile it using make:
[18:24:54] finger.c ...
In file included from finger.c:10:0:
../src/include/merc.h:5149:13: warning: inline function ‘check_toughness’ declared but never defined
inline int check_toughness args( ( CD *ch, CD *victim, int dam));
^~~~~~~~~~~~~~~
[18:24:54] Linking Executable ...
obj/fight.o: In function `group_gain':
tbw/reloaded/src/fight.c:5514: undefined reference to `xp_compute'
tbw/reloaded/src/fight.c:5516: undefined reference to `xp_compute'
tbw/reloaded/src/fight.c:5518: undefined reference to `xp_compute'
obj/fight.o: In function `one_hit':
tbw/reloaded/src/fight.c:2457: undefined reference to `check_toughness'
obj/mage.o: In function `do_chant':
tbw/reloaded/src/mage.c:345: undefined reference to `check_toughness'
tbw/reloaded/src/mage.c:361: undefined reference to `check_toughness'
tbw/reloaded/src/mage.c:377: undefined reference to `check_toughness'
tbw/reloaded/src/mage.c:393: undefined reference to `check_toughness'
obj/mage.o:tbw/reloaded/src/mage.c:409: more undefined references to `check_toughness' follow
obj/update.o: In function `mobile_update':
tbw/reloaded/src/update.c:756: undefined reference to `werewolf_regen'
obj/powerl.o: In function `do_planarstorm':
tbw/reloaded/src/powerl.c:680: undefined reference to `check_toughness'
collect2: error: ld returned 1 exit status
Makefile:27: recipe for target '../src/reloaded' failed
make: *** [../src/reloaded] Error 1
The codebase and the referenced files are huge, so I figured it wouldn't make sense to attach them just yet, but if required I can definitely provide them.
For the record, those functions like "check_toughness" and "xp_compute" are definitely defined within those files after a few thousand LOC.
Would appreciate any suggestions, thank you!

Thank you to everyone who came in with suggestions!
The simplest answer was provided by rici:
That is probably the result of the code using the old idiosyncratic gcc semantics for inline. Try compiling with --std=gnu89 (if you are using gcc).
Adding that to the Makefile cleared up all the errors and resulted in a successful compile.

Related

Linker Complains Undefined Reference Under MINIX3.2.1

As you may imagine, it's a homework of Operating Systems and I'm asked to add function key Shift+F7 to show the number of running process.
I read the source code of command ps on GitHub (MINIX version 3.2.1) and try to implement a function that can finish the task in file /usr/src/servers/is/dmp_kernel.c. However, when I try to run make, it complains about undefined reference like
dmp_kernel.o: In function `running_proc_num':
dmp_kernel.c:(.text+0x1e): undefined reference to `chdir'
dmp_kernel.c:(.text+0x42): undefined reference to `fopen'
dmp_kernel.c:(.text+0x72): undefined reference to `fscanf'
dmp_kernel.c:(.text+0x8b): undefined reference to `fclose'
dmp_kernel.c:(.text+0xc4): undefined reference to `log10'
dmp_kernel.c:(.text+0xcc): undefined reference to `ceil'
dmp_kernel.c:(.text+0x119): undefined reference to `log10'
dmp_kernel.c:(.text+0x121): undefined reference to `ceil'
dmp_kernel.c:(.text+0x170): undefined reference to `fopen'
dmp_kernel.c:(.text+0x1bc): undefined reference to `fscanf'
dmp_kernel.c:(.text+0x1d3): undefined reference to `fclose'
dmp_kernel.c:(.text+0x210): undefined reference to `wait'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've already include the headers like stdio.h, math.h, unistd.h, and sys/wait.h. In the answer to one Stack Overflow question, I learnt that the reason for this issue is that the linker doesn't link a complete C library under MINIX. However, I usually use CMake and really have no idea to solve such issue. I don't even know how to "explicitly" link the functions using make.
I really look forward for your help!
The Makefile looks like
.include <bsd.own.mk>
PROG= is
SRCS= main.c dmp.c dmp_kernel.c dmp_pm.c dmp_fs.c dmp_rs.c dmp_ds.c dmp_vm.c
DPADD+= ${LIBSYS}
LDADD+= -lsys
MAN=
BINDIR?= /sbin
CPPFLAGS.dmp_kernel.c+= -I${NETBSDSRCDIR}
CPPFLAGS.dmp_rs.c+= -I${NETBSDSRCDIR}
CPPFLAGS.dmp_vm.c+= -I${NETBSDSRCDIR}
# This setting must match the kernel's, as it affects the IRQ hooks table size.
.if ${USE_APIC} != "no"
CFLAGS+= -DUSE_APIC
.endif
.include <minix.service.mk>

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.

undefined reference to '__imp_fmi2_import_free'

I have been trying to compile and link a test file written in c and which can communicate with FMILibrary of JModelica. I was able to compile and link it and run it in linux systems. coming to the Windows, I am using mingw-64 compiler to compile and link the test file with FMILibrary, but I am getting undefined reference errors. I was able to compile and run it on 32 bit mingw but I need to compile and link it with 64 bit compiled binaries.
My command goes like this:
gcc -I <..fmilib\include> -L <..fmilib\lib> -lfmilib -o testfile testfile.c fmivars.c
And the following is the result that is getting printed out as a result
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x9b): undefined reference to `__imp_fmi2_import_get_real'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0xd6): undefined reference to `__imp_fmi2_import_get_integer'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x111): undefined reference to `__imp_fmi2_import_get_boolean'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x14c): undefined reference to `__imp_fmi2_import_get_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x187): undefined reference to `__imp_fmi2_import_set_real'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x1c2): undefined reference to `__imp_fmi2_import_set_integer'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x1fd): undefined reference to `__imp_fmi2_import_set_boolean'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x238): undefined reference to `__imp_fmi2_import_set_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x27a): undefined reference to `__imp_fmi2_import_new_discrete_states'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x2b6): undefined reference to `__imp_fmi2_import_collect_model_counts'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x30b): undefined reference to `__imp_fmi2_status_to_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x37e): undefined reference to `__imp_jm_vsnprintf'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x395): undefined reference to `__imp_fmi2_status_to_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x437): undefined reference to `__imp_jm_vsnprintf'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x556): undefined reference to `__imp_fmi2_import_get_version'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x575): undefined reference to `__imp_fmi2_import_get_types_platform'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x594): undefined reference to `__imp_fmi2_import_get_number_of_continuous_states'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x5a8): undefined reference to `__imp_fmi2_import_get_number_of_event_indicators'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x64a): undefined reference to `__imp_fmi2_import_instantiate'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x690): undefined reference to `__imp_fmi2_import_set_debug_logging'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x6af): undefined reference to `__imp_fmi2_status_to_string'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x6df): undefined reference to `__imp_fmi2_import_set_debug_logging'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x718): undefined reference to `__imp_fmi2_import_setup_experiment'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x733): undefined reference to `__imp_fmi2_import_enter_initialization_mode'
Is there any macro or anything set on the FMILibrary to compile with 64 bit mingw compiler on windows 64 bit? Thanks.
Assuming the library libfmilib.x.y.z provided the missing symbols then on the linker's/compiler's command line move it to the right of the .c-files requiring them
gcc -I <..fmilib\include> -L <..fmilib\lib> -o testfile testfile.c fmivars.c -lfmilib
Thank you everyone for helping me. I finally solved my problem and was able to run the code. I installed dependency walker as suggested by #PilouPili and found out that my application is looking for the library in the same folder(I don't know for some reason) and it was unable to find it. So, I copied all the static and dynamic libraries and I pasted in the folder where my testfile is. Also I changed the command line as suggested by #alk and moved the -lfmilib to the end. And I used the dynamic library instead of static one. But anyways my application runs now. Thank you so much for helping out.

how to use "make and building executables" in Linux work [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 6 years ago.
i tried to use make on my c source code and created executable file. but the executable file did not work the intended task. even if the make file compiled and produced the executable file when i try to compile the .c file individually it gave many undefined reference problem
The errors are
/tmp/cc4tx0BG.o: In function `main':
cubist.c:(.text+0xdc): undefined reference to `Of'
cubist.c:(.text+0xe7): undefined reference to `Of'
cubist.c:(.text+0xfa): undefined reference to `Of'
cubist.c:(.text+0x10f): undefined reference to `KRInit'
cubist.c:(.text+0x114): undefined reference to `ExecTime'
cubist.c:(.text+0x127): undefined reference to `PrintHeader'
cubist.c:(.text+0x139): undefined reference to `Of'
[...]
cubist.c:(.text+0xb79): undefined reference to `MaxAtt'
cubist.c:(.text+0xb83): undefined reference to `InitialiseEnvData'
cubist.c:(.text+0xb8a): undefined reference to `XVAL'
cubist.c:(.text+0xb93): undefined reference to `CrossVal'
cubist.c:(.text+0xb9a): undefined reference to `SingleCttee'
cubist.c:(.text+0xb9f): undefined reference to `ExecTime'
cubist.c:(.text+0xbab): undefined reference to `Of'
collect2: error: ld returned 1 exit status
please, could any body tells how to use make and building executables in Linux work.
I think (not sure) that you are saying that you successfully produced an executable using Make (at least that's how I interpret "use make on my c source code and created executable file" -- do correct me if I'm wrong!). If that's the case, invoke make like this: make -B --trace, and you'll see the exact commands that were used to build the executable, and then you'll hopefully know which compiler/linker flags or libraries you missed while trying to build stuff manually.

Lua compilation link error

When I try to compile a little lua program, I get these errors :
/usr/lib//liblua52.so: undefined reference to `dlsym'
/usr/lib//liblua52.so: undefined reference to `dlerror'
/usr/lib//liblua52.so: undefined reference to `dlopen'
/usr/lib//liblua52.so: undefined reference to `dlclose'
Of course, I link with -ldl. I have lua5.2-dev installed on my ubuntu.
If you need any more infos ask me.
Thanks!
When I try to compile a little lua program, I get these errors
No. You get these errors when you link the program.
The fix is to add -ldl at the end of your link line.
The easy way to get this error is to have your PLAT variable set wrong in the Makefile. You need to set it in the top level Makefile and the src/Makefile.
The legal values show up about 10 lines down from the definition.
Ensure -ldl is exactly at the end of your link line as Employed Russian mentioned

Resources