newbie compiling problems

Posted by Gdub on Sat 10 Feb 2024 08:07 PM — 25 posts, 46,025 views.

#0
Hoping someone has the patience to help me with some compiling problems. I have a heavily modified SMAUG code base that I found while cleaning out and old storage locker. I'm keen to start fiddling again. I'm using Win10 and cygwin.

I made it this far - skills are very dusty so apologies in advance if I'm being daft.
[code]
$ make smaug
Makefile:49: warning: ignoring prerequisites on suffix rule definition
<snip lots of warnings>
gcc -c  -O -g3 -Wall -Wuninitialized   -DREQUESTS -DSMAUG  -DNOCRYPT act_move.c
In file included from act_move.c:23:
act_move.c: In function ‘grab_word’:
act_move.c:175:21: warning: array subscript has type ‘char’ [-Wchar-subscripts]
  175 |     while ( isspace(*argument) )
      |                     ^~~~~~~~~
act_move.c:193:21: warning: array subscript has type ‘char’ [-Wchar-subscripts]
  193 |     while ( isspace(*argument) )
      |                     ^~~~~~~~~
act_move.c: In function ‘decorate_room’:
act_move.c:297:41: warning: ‘*’ in boolean context, suggest ‘&&’ instead [-Wint-in-bool-context]
  297 |               switch( number_range(1, 2 * (iRand == nRand -1) ? 1 : 2) )
      |                                       ~~^~~~~~~~~~~~~~~~~~~~~
act_move.c: In function ‘rev_exit’:
act_move.c:400:15: warning: trigraph ??> ignored, use -trigraphs to enable [-Wtrigraphs]
  400 |     return "<???>";
      |
act_move.c: In function ‘generate_exit’:
act_move.c:628:25: error: lvalue required as left operand of assignment
  628 |     (EXIT_DATA *) pexit = xit;
      |                         ^
act_move.c: In function ‘do_climb’:
act_move.c:2468:10: warning: variable ‘found’ set but not used [-Wunused-but-set-variable]
 2468 |     bool found;
      |          ^~~~~
act_move.c: In function ‘do_enter’:
act_move.c:2499:10: warning: variable ‘found’ set but not used [-Wunused-but-set-variable]
 2499 |     bool found;
      |          ^~~~~
act_move.c: In function ‘do_leave’:
act_move.c:2538:10: warning: variable ‘found’ set but not used [-Wunused-but-set-variable]
 2538 |     bool found;
      |          ^~~~~
make: *** [Makefile:49: act_move.o] Error 1
[/code]
Amended on Wed 14 Feb 2024 06:41 AM by Gdub
Australia Forum Administrator #1
You've only got one error, which I asked ChatGPT about (to save myself having to think). :)




The error message you're encountering in your C code, specifically the "lvalue required as left operand of assignment," suggests a problem with the assignment operation at line 628. In C, an lvalue is an expression that refers to a memory location and allows us to take the address of that location. It's basically something that can appear on the left-hand side of an assignment.

The line (EXIT_DATA *) pexit = xit; seems to be attempting a cast and then an assignment. The issue here is that the casting operation (EXIT_DATA *) pexit creates a temporary value, not an lvalue. You cannot assign a value to a cast like this because the result of a cast is not a memory location that you can assign to.

If pexit is a pointer of a different type and you want to assign xit to it, you should first cast xit to the type of pexit. For example:


pexit = (EXIT_DATA *) xit;


This assumes xit is of a type that can be meaningfully cast to EXIT_DATA*. This code assigns the value of xit (after casting it to EXIT_DATA*) to pexit. Make sure that this cast is safe and that the types are compatible in a way that makes sense for your program.




This sounds like reasonable advice to me.
Amended on Sat 10 Feb 2024 11:13 PM by Nick Gammon
#2
Thank you Nick!

I could have sworn I saved a compliable version of it. It is possible the cygwin of ~20 years ago would have handled that differently? Or more likely that I saved the wrong version? :/

Anyways, thank you for the prompt reply. I'll keep working through it and report back.
#3
I worked through a few more (very odd errors) and have been using chatgpt as a helpful guide - thanks for the tip.

I'm now stuck on a macro that handles linked lists

errors:

In file included from ban.c:24:
ban.c: In function ‘dispose_ban’:
mud.h:3141:33: error: lvalue required as left operand of assignment
3141 | (first) = (link)->next;\
| ^
ban.c:1266:3: note: in expansion of macro ‘UNLINK’
1266 | UNLINK(pban,(type==BAN_SITE)?first_ban:(type==BAN_CLASS)?first_ban_class:first_ban_race,(type==BAN_SITE)?last_ban:(type==BAN_CLASS)?last_ban_class:last_ban_race, next, prev );
| ^~~~~~
mud.h:3145:33: error: lvalue required as left operand of assignment
3145 | (last) = (link)->prev; \
| ^


macros:

#define UNLINK(link, first, last, next, prev) \
do \
{ \
if ( !(link)->prev )\
(first) = (link)->next;\
else \
(link)->prev->next = (link)->next; \
if ( !(link)->next ) \
(last) = (link)->prev; \
else \
(link)->next->prev = (link)->prev; \
} while(0)


use of macro:

void dispose_ban( BAN_DATA *pban , int type)
{
if ( !pban )
return;

if ( type != BAN_SITE && type != BAN_CLASS && type != BAN_RACE )
{
bug("Dispose_ban: Unknown Ban Type %d.", type );
return;
}

UNLINK(pban,(type==BAN_SITE)?first_ban:(type==BAN_CLASS)?first_ban_class:first_ban_race,(type==BAN_SITE)?last_ban:(type==BAN_CLASS)?last_ban_class:last_ban_race, next, prev );
free_ban( pban );
return;
}

chatgpt has no suggestions for me.
Australia Forum Administrator #4

GPT4 seems to handle it:


The error you’re encountering is related to the UNLINK macro. The issue seems to be with the (first) and (last) assignments within the macro. The macro expects first and last to be lvalues, meaning they need to be assignable. However, in your dispose_ban function, you’re passing expressions to the macro that are not lvalues.

The error occurs because the expressions (type==BAN_SITE)?first_ban:(type==BAN_CLASS)?first_ban_class:first_ban_race and (type==BAN_SITE)?last_ban:(type==BAN_CLASS)?last_ban_class:last_ban_race used for first and last are conditional expressions. These are not lvalues because they don’t directly refer to a modifiable memory location. They evaluate to a value depending on the condition, but you cannot assign a value to them directly.

To resolve this issue, you might need to use temporary pointers that store the result of these conditional expressions. You can then pass these temporary pointers to the UNLINK macro. Here’s an example of how you might modify your dispose_ban function:

void dispose_ban(BAN_DATA *pban, int type)
{
    BAN_DATA **first_temp, **last_temp;

    if (!pban)
        return;

    if (type != BAN_SITE && type != BAN_CLASS && type != BAN_RACE)
    {
        bug("Dispose_ban: Unknown Ban Type %d.", type);
        return;
    }

    // Determine the correct first and last pointers based on the type
    if (type == BAN_SITE)
    {
        first_temp = &first_ban;
        last_temp = &last_ban;
    }
    else if (type == BAN_CLASS)
    {
        first_temp = &first_ban_class;
        last_temp = &last_ban_class;
    }
    else // BAN_RACE
    {
        first_temp = &first_ban_race;
        last_temp = &last_ban_race;
    }

    // Now use the temporary pointers in the UNLINK macro
    UNLINK(pban, *first_temp, *last_temp, next, prev);

    free_ban(pban);
    return;
}

In this modified version, first_temp and last_temp are pointers to pointers. They are set to point to the appropriate first_ban, first_ban_class, first_ban_race, last_ban, last_ban_class, or last_ban_race based on the type. When you pass *first_temp and *last_temp to the UNLINK macro, you are passing modifiable lvalues, which should resolve the error.

Australia Forum Administrator #5
Gdub said:

I could have sworn I saved a compliable version of it. It is possible the cygwin of ~20 years ago would have handled that differently? Or more likely that I saved the wrong version? :/


Quite likely. The error and warning checking by the C and C++ compilers continues to evolve (improve) so that dodgy constructs are now errors or warnings. The underlying code presumably still works, however you could always consider the warnings as indications of things that might possibly cause trouble later.

I've had code that used to compile perfectly well fail when compiled on newer compilers.
Amended on Sun 11 Feb 2024 08:46 PM by Nick Gammon
Australia Forum Administrator #6

An alternative, and this is my idea and not ChatGPT’s, is to not try to do all three ban types in one line, but rather:

void dispose_ban(BAN_DATA *pban, int type)
{
    if (!pban)
        return;

    if (type == BAN_SITE)
    {
        UNLINK(pban, first_ban, last_ban, next, prev);
    }
    else if (type == BAN_CLASS)
    {
        UNLINK(pban, first_ban_class, last_ban_class, next, prev);
    }
    else if (type == BAN_RACE)
    {
        UNLINK(pban, first_ban_race, last_ban_race, next, prev);
    }
    else
    {
        bug("Dispose_ban: Unknown Ban Type %d.", type);
        return;
    }

    free_ban(pban);
    return;
}
#7
Thank you Nick. Your solution appears to have worked and I'm on to the next set of errors :)

I will attempt to resolve them on my own so I don't become dependent on your wisdom :) but I'll report back if I get stuck.

Cheers.
#8
I've successfully compiled!

There were a few multiple declaration errors so I tried using the extern keyword. That didn't work so I declared them as static and voila!

Now onto seeing if I can run it and connect.
Australia Forum Administrator #9
Gdub said:

There were a few multiple declaration errors so I tried using the extern keyword. That didn't work so I declared them as static and voila!


It would depend on the context. If the variable is supposed to be shared across compilation units then making them static will stop that sharing.
#10
new and perplexing issue.

I compiled the .exe with no errors.
I ran the .exe from the command shell and got and error that cygwin.dll missing.
I copied cygwin.dll over to the src directory from the recent cygwin install.
I tried to run the .exe again and got an error re: requests pipe failure
I reviewed my code changes, changed nothing - make clean and make smaug
I got a an error on compile from the makefile!


Makefile:49: warning: ignoring prerequisites on suffix rule definition
gcc -c  -O -g3 -Wall -Wuninitialized   -DREQUESTS -DSMAUG  -DNOCRYPT act_comm.c
make: *** [Makefile:49: act_comm.o] Error 1



I made no changes to the make file... what have I done?
Australia Forum Administrator #11

Not sure. This is what ChatGPT had to say:


This error message and warning are coming from a Makefile used in compiling a C program with GCC (GNU Compiler Collection). Let’s break down what each part means:

  1. Makefile:49: warning: ignoring prerequisites on suffix rule definition
    • This is a warning about the way a suffix rule is defined in your Makefile. Suffix rules are a way to define how to convert one type of file to another, based on their file extensions. For example, a rule to compile .c files into .o (object) files. The warning is likely because the prerequisites (dependencies) for a suffix rule are not specified correctly. This might not stop the make process but indicates potential issues in the Makefile.
  2. gcc -c -O -g3 -Wall -Wuninitialized -DREQUESTS -DSMAUG -DNOCRYPT act_comm.c
    • This line is the actual command being executed. It’s calling gcc (the GNU C Compiler) to compile the act_comm.c source file. The flags used are:
      • -c: Compile and assemble, but do not link.
      • -O: Enable compiler optimizations.
      • -g3: Produce debugging information in the operating system’s native format.
      • -Wall: Enable all compiler’s warning messages.
      • -Wuninitialized: Warn if an uninitialized variable is used.
      • -DREQUESTS, -DSMAUG, -DNOCRYPT: Define these preprocessor macros.
  3. make: *** [Makefile:49: act_comm.o] Error 1
    • This is the actual error message from make, indicating that the compilation failed. The Error 1 part is a general error code from gcc meaning that there were problems during the compilation. This error is associated with the target act_comm.o, which is defined on line 49 of the Makefile.

To resolve this issue, you will need to:

  • Check the definition of the rule at line 49 in the Makefile. Ensure that the syntax is correct and all necessary prerequisites are specified.
  • Look at the preceding lines of the output (not shown in your message) for any specific gcc error messages. These messages will provide more detail about why the compilation of act_comm.c failed.
  • Address any syntax errors, missing dependencies, or other issues in act_comm.c as indicated by the gcc error messages.
  • If the issue is with the Makefile’s syntax or structure, you may need to consult the GNU Make manual or other resources on writing Makefiles.
#12
When I delete the cywin.dll from the src folder it will compile again. Seems like a conflict with the .DLL?
Australia Forum Administrator #13
What operating system are you using? It sounds like a Windows version.

Are you compiling using the command shell or the Cygwin shell? If it compiles under Cygwin it shouldn't be asking for cygwin.dll when you go to execute it.
Australia Forum Administrator #14
The Cygwin shell normally puts the appropriate DLLs in your path.

Alternatively, maybe you cross-compiled for one operating system (not the one you are using), which means it might compile OK but not run.
#15
Nick Gammon said:

What operating system are you using? It sounds like a Windows version.

Are you compiling using the command shell or the Cygwin shell? If it compiles under Cygwin it shouldn't be asking for cygwin.dll when you go to execute it.


Windows 11 64bit home edition

I'm using cygwin to compile. Should I maybe resinstall cygwin?
Australia Forum Administrator #16
No, if it compiles OK. Are you also using the Cygwin shell to run it?
#17
Nick Gammon said:

No, if it compiles OK. Are you also using the Cygwin shell to run it?


it gives 0 feedback when I run it via cygwin shell using:


cd ../area
../src/smaug


The only feedback I get is running ./smaug from the windows powershell where it gives me this error.


PS C:\Conquest_SRC\Conquest\dist\src> ./smaug
Wed Feb 14 12:53:44 2024 :: Booting Database
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Wed Feb 14 12:53:44 2024 :: [*****] BOOT: ---------------------[ Boot Log ]--------------------
Wed Feb 14 12:53:44 2024 :: Loading commands
Wed Feb 14 12:53:44 2024 :: Loading sysdata configuration...
Wed Feb 14 12:53:44 2024 :: Loading socials
Wed Feb 14 12:53:44 2024 :: Loading skill table
Wed Feb 14 12:53:44 2024 :: Sorting skill table...
Wed Feb 14 12:53:44 2024 :: Remapping slots to sns
Wed Feb 14 12:53:44 2024 :: Loading classes
Wed Feb 14 12:53:44 2024 :: Loading races
Wed Feb 14 12:53:44 2024 :: Loading herb table
Wed Feb 14 12:53:44 2024 :: Loading tongues
Wed Feb 14 12:53:44 2024 :: Making wizlist
Wed Feb 14 12:53:44 2024 :: Initializing request pipe
Wed Feb 14 12:53:44 2024 :: [*****] BUG: REQUEST pipe not found
PS C:\Conquest_SRC\Conquest\dist\src>


There are no log files being generated either :/
Australia Forum Administrator #18

I would be running from the Cygwin shell personally. No feedback sounds odd. Maybe it’s running in the background? Try: ps -waux and see if you can spot smaug there. Maybe:

ps -waux | grep smaug
Amended on Wed 14 Feb 2024 11:11 PM by Nick Gammon
Australia Forum Administrator #19
 PS C:\Conquest_SRC\Conquest\dist\src> ./smaug
 Wed Feb 14 12:53:44 2024 :: Booting Database

You should still be running from the area directory, which you aren’t there.

#20
Nick Gammon said:

> PS C:\Conquest_SRC\Conquest\dist\src> ./smaug
> Wed Feb 14 12:53:44 2024 :: Booting Database

You should still be running from the area directory, which you aren't there.



PS C:\Conquest_SRC\Conquest\dist\area> ../src/smaug
Wed Feb 14 22:27:03 2024 :: Booting Database
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Wed Feb 14 22:27:03 2024 :: [*****] BOOT: ---------------------[ Boot Log ]--------------------
Wed Feb 14 22:27:03 2024 :: Loading commands
Wed Feb 14 22:27:03 2024 :: Loading sysdata configuration...
Wed Feb 14 22:27:03 2024 :: Loading socials
Wed Feb 14 22:27:03 2024 :: Loading skill table
Wed Feb 14 22:27:03 2024 :: Sorting skill table...
Wed Feb 14 22:27:03 2024 :: Remapping slots to sns
Wed Feb 14 22:27:03 2024 :: Loading classes
Wed Feb 14 22:27:03 2024 :: Loading races
Wed Feb 14 22:27:03 2024 :: Loading herb table
Wed Feb 14 22:27:03 2024 :: Loading tongues
Wed Feb 14 22:27:03 2024 :: Making wizlist
Wed Feb 14 22:27:03 2024 :: Initializing request pipe
Wed Feb 14 22:27:03 2024 :: [*****] BUG: REQUEST pipe not found
PS C:\Conquest_SRC\Conquest\dist\area>
#21
Nick Gammon said:

I would be running from the Cygwin shell personally. No feedback sounds odd. Maybe it's running in the background? Try: ps -waux and see if you can spot smaug there. Maybe:

```bash
ps -waux | grep smaug
```


I'm really out of my element here but I'll keep trying whatever you suggest.


user@DESKTOP-7RPHHGB /cygdrive/c/conquest_src/conquest/dist/src
$ cd ../

user@DESKTOP-7RPHHGB /cygdrive/c/conquest_src/conquest/dist
$ cd area

user@DESKTOP-7RPHHGB /cygdrive/c/conquest_src/conquest/dist/area
$ ../src/smaug

user@DESKTOP-7RPHHGB /cygdrive/c/conquest_src/conquest/dist/area
$ ps -waux | grep smaug
ps: unknown option -- w
Try `ps --help' for more information.

user@DESKTOP-7RPHHGB /cygdrive/c/conquest_src/conquest/dist/area
$ ps grep smaug
      PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND
     1235    1234    1235      61320  pty0      197609 22:26:37 /usr/bin/bash
     1234       1    1234      14024  ?         197609 22:26:37 /usr/bin/mintty
     1242    1235    1242      69948  pty0      197609 22:30:04 /usr/bin/ps

user@DESKTOP-7RPHHGB /cygdrive/c/conquest_src/conquest/dist/area

#22
Gdub said:

Nick Gammon said:

I would be running from the Cygwin shell personally. No feedback sounds odd. Maybe it's running in the background? Try: ps -waux and see if you can spot smaug there. Maybe:

```bash
ps -waux | grep smaug
```


I'm really out of my element here but I'll keep trying whatever you suggest.


user@DESKTOP-7RPHHGB /cygdrive/c/conquest_src/conquest/dist/src
$ cd ../

user@DESKTOP-7RPHHGB /cygdrive/c/conquest_src/conquest/dist
$ cd area

user@DESKTOP-7RPHHGB /cygdrive/c/conquest_src/conquest/dist/area
$ ../src/smaug

user@DESKTOP-7RPHHGB /cygdrive/c/conquest_src/conquest/dist/area
$ ps -waux | grep smaug
ps: unknown option -- w
Try `ps --help' for more information.

user@DESKTOP-7RPHHGB /cygdrive/c/conquest_src/conquest/dist/area
$ ps grep smaug
      PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND
     1235    1234    1235      61320  pty0      197609 22:26:37 /usr/bin/bash
     1234       1    1234      14024  ?         197609 22:26:37 /usr/bin/mintty
     1242    1235    1242      69948  pty0      197609 22:30:04 /usr/bin/ps

user@DESKTOP-7RPHHGB /cygdrive/c/conquest_src/conquest/dist/area






user@DESKTOP-7RPHHGB /cygdrive/c/conquest_src/conquest/dist/area
$ bash grep ps -waux | grep  smaug
/usr/bin/grep: /usr/bin/grep: cannot execute binary file

user@DESKTOP-7RPHHGB /cygdrive/c/conquest_src/conquest/dist/area
$ bash

user@DESKTOP-7RPHHGB /cygdrive/c/conquest_src/conquest/dist/area
$ ps -waux|grep smaug
ps: unknown option -- w
Try `ps --help' for more information.
Australia Forum Administrator #23

Oh well, then since it doesn’t like ‘w’:

 ps -aux | grep smaug
Australia Forum Administrator #24

And how big is smaug?

ls -lh ../src/smaug