Language: 
To browser these website, it's necessary to store cookies on your computer.
The cookies contain no personal information, they are required for program control.
  the storage of cookies while browsing this website, on Login and Register.

Author Topic:  Compile from source on linux ubuntu  (Read 768 times)

0 Members and 1 Guest are viewing this topic.

zaisty

« on: 20, May 2023, 01:47:31 »
I have problem with compile process on ubuntu 22.04 LTS.

What I done so far?

1. Install all the libs that nedded to compile process:

sudo apt install -y libsdl2-2.0-0 libsdl2-dev gcc-multilib libsdl1.2-dev libsdl-mixer1.2-dev libsdl-image1.2-dev libphysfs-dev libcurl4-gnutls-dev


2. Open terminal in make/linux folder and run this commands:

./bootstrap
./configure

And it seems ok for now.

3. But when I try to run 'make' command I have this error at the end:

src/client.c:451: undefined reference to `sprintf_s'
collect2: error: ld returned 1 exit status
make: *** [Makefile:606: daimonin] Błąd 1


Try to search internet but with no result.
How to end compile process and finally run Daimonin?

Dolfo

« Reply #1 on: 20, May 2023, 07:53:12 »
sprintf_s needs

#include <stdio.h>

This should be normaly at the beginning of src/client.c file.  This undefined reference error is mostly in relation to your linker. Somehow your linker didn't find the reference to the stdio.h library.

You can use linux command locate or find to check if and where you have the stdio.h file.

sudo find / -name 'stdio.h'

Looks like your compiler didnt find the file or the file is not installed on your system. Linker problems are a pain, but its always the same error logic behind, where the linker can't find a file.

So check if your system has stdio.h. Then inform the compiler/linker where to find the file.

Here is the same problem.

https://askubuntu.com/questions/369462/gcc-problem-stdio-h-not-found
Don't believe the shit, you hear in mainstream. Believe your own body. Your body is speaking always the true to you. But you need to understand your body. Hear to your body, not to your ego. And when body is calling to you: "Hey something is wrong!" find the reason(s) for that. Man in White don't go for that, they don't want to heal you. They want earn money and sell you medicine, you should take rest of your life. You are not the patient, you are their customer. Never forget this!

zaisty

« Reply #2 on: 20, May 2023, 15:07:00 »
Thanks.
Can You explain in simple way how to inform compiler where I have stdio.h file.
It's in

/usr/include/c++/11/tr1/stdio.h
/usr/include/stdio.h
/usr/include/x86_64-linux-gnu/bits/stdio.h

I try 'export LIBDIR=/usr/include:$LIBDIR' and then run make but it's same error show.

Dolfo

« Reply #3 on: 20, May 2023, 15:39:54 »
To my defense, last time i worked with a linux system is years ago, so i am not 100% sure, if i am right.

I would first try to reduce this problem to a smaller code snippet. Here is a nice short example using sprintf and #include <stdio.h>

https://www.geeksforgeeks.org/sprintf-in-c/

Perhaps you try to compile first this example, so we see if i am right or wrong?

Sometimes linker errors can also triggered, if you link the librarys in wrong directions. But perhaps you check first the small example, if this launch the same error?
« Last Edit: 20, May 2023, 15:43:53 by Dolfo »
Don't believe the shit, you hear in mainstream. Believe your own body. Your body is speaking always the true to you. But you need to understand your body. Hear to your body, not to your ego. And when body is calling to you: "Hey something is wrong!" find the reason(s) for that. Man in White don't go for that, they don't want to heal you. They want earn money and sell you medicine, you should take rest of your life. You are not the patient, you are their customer. Never forget this!

asuratva

« Reply #4 on: 21, May 2023, 13:54:47 »
After running ./configure, but before running 'make', edit the generated 'Makefile' to add the option -fcommon to CFLAGS.

It should look like:
Code: [Select]
...
CFALGS = -g -O2 -fcommon
...

Also edit the file '.../client_0.10.9/src/client.c' at line 451 to change 'sprintf_s' to 'snprintf'. Leave the function arguments as they are.

It should be:
Code: [Select]
...
                            snprintf(cmd, TINY_BUF, "ready_skill %s", params);
...

Then run 'make' and it should work. (You will have to run 'make clean' first if you've already run 'make' before)
« Last Edit: 21, May 2023, 14:38:53 by asuratva »

Dolfo

« Reply #5 on: 22, May 2023, 02:05:21 »
So i was wrong. There is no problem with the linker to find the file, instead we have an undefined function call, because of the wrong parameters behind sprintf. Found this.
#include <stdio.h>
int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
int sprintf(char *str, const char *format, ...);
int snprintf(char *str, size_t size, const char *format, ...);

Who uploaded buggy not compileable code?  :P
Don't believe the shit, you hear in mainstream. Believe your own body. Your body is speaking always the true to you. But you need to understand your body. Hear to your body, not to your ego. And when body is calling to you: "Hey something is wrong!" find the reason(s) for that. Man in White don't go for that, they don't want to heal you. They want earn money and sell you medicine, you should take rest of your life. You are not the patient, you are their customer. Never forget this!

asuratva

« Reply #6 on: 22, May 2023, 07:14:52 »
sprintf_s and snprintf take the same parameters, but snprintf is available on all platforms as part of standard C library. sprintf_s may or may not be available as it is an optional specification of std C and not required. There are minor differences b/w the 2 functions (eg. return values may be slightly different on error) but for the purposes of the code used here, they are interchangeable.

Dolfo

« Reply #7 on: 22, May 2023, 17:28:13 »
Ok, but both functions using same parameter i must contradict. All websites i found in relation to function sprintf_s haven't the second parameter " size_t size " like snprintf has?

Perhaps its an old conversation worked in past with sprintf_s? But currently the web say this:

int sprintf(char *str, const char *format, ...);
int snprintf(char *str, size_t size, const char *format, ...);

And that's not the same.  :o
« Last Edit: 22, May 2023, 17:29:47 by Dolfo »
Don't believe the shit, you hear in mainstream. Believe your own body. Your body is speaking always the true to you. But you need to understand your body. Hear to your body, not to your ego. And when body is calling to you: "Hey something is wrong!" find the reason(s) for that. Man in White don't go for that, they don't want to heal you. They want earn money and sell you medicine, you should take rest of your life. You are not the patient, you are their customer. Never forget this!

asuratva

« Reply #8 on: 22, May 2023, 22:57:52 »
sprintf_s is different from sprintf. It's a safe version introduced in C11 standard.
See here for reference: https://en.cppreference.com/w/c/io/fprintf

Dolfo

« Reply #9 on: 23, May 2023, 00:27:03 »
Ah ok, this is really a mess. I compared sprintf with snprintf. But you changed sprintf_s to snprintf. So my mistake. C is really a pain. This function names are confusing. If you read this function names longer, you can only bump your head against a wall.

So you used the function from c99 standard now instead of the c11 standard? I only try to understand. You choosed the unsafe and older function, which works, where the newer and safe function fails?  :o
Don't believe the shit, you hear in mainstream. Believe your own body. Your body is speaking always the true to you. But you need to understand your body. Hear to your body, not to your ego. And when body is calling to you: "Hey something is wrong!" find the reason(s) for that. Man in White don't go for that, they don't want to heal you. They want earn money and sell you medicine, you should take rest of your life. You are not the patient, you are their customer. Never forget this!

asuratva

« Reply #10 on: 23, May 2023, 09:42:44 »
sprintf is unsafe because it doesn't check the length of the strings that are passed to it as parameters.

snprintf is safe version of sprintf.

sprintf_s is the same as snprintf but adds some additional runtime checks that give better error messages, which makes it easier debug or to handle errors at runtime.

The way it is used in the code, the extra features sprintf_s provides over snprintf are pointless since the return value is being ignored anyway. Replacing with snprintf makes the code more portable without sacrificing anything.

Renfield

« Reply #11 on: 05, June 2023, 00:41:14 »
Just wanted to confirm that this indeed worked for me. Fortunately this thread was linked multiple times in the chat after logging in, so I found it after stumbling over the same compile error.

Tags:
 

Related Topics

  Subject / Started by Replies Last post
8 Replies
1346 Views
Last post 27, April 2006, 04:44:07
by robed
1 Replies
705 Views
Last post 23, June 2006, 00:36:23
by smacky
9 Replies
963 Views
Last post 15, February 2007, 03:58:25
by reacocard
4 Replies
847 Views
Last post 06, September 2007, 02:39:06
by hakware2000
16 Replies
3953 Views
Last post 12, November 2007, 22:23:45
by Anchakor