Linking cannot find the appropriate library file

Asked by Mike Gilmer on 2017-06-05

I've installed gcc-arm on a Fedora machine. I can compile basic programs, however I've now included a call to sscanf and the build process fails at link time.

Of course stdio.h is included in the c file and no warnings at compile time. so the compiler finds the header file where it should.

I just get the link-time error: undefined reference to 'sscanf'
I suppose the linker is unable locate the appropriate library file. However I cannot tell just which file that is for this environment. I've tried adding various paths with '-L' to no avail.

Any help would be appreciated.


Question information

English Edit question
GNU Arm Embedded Toolchain Edit question
No assignee Edit question
Last query:
Last reply:

Can you paste the link command you are using? A reduced preprocessed testcase (use -save-temps and send the .i file) could also help.

Best regards.

Mike Gilmer (mike65535) said : #2

I am working on a reduced test case.

Upon further study, it seems the file libc.a *is* located during link and used properly, since there are other functions within my source code (memset for ex.) that are being found and linked successfully.

Is there something about sscanf and strncpy that would distinguish them for failure?

Hi Mike,

Could you show us the output when adding -Wl,--trace on the command-line? Or at least add --print-multi-directory and give us the output.

Best regards.

Mike Gilmer (mike65535) said : #4

Thanks for your patience and time THomas...

output (with some modifications to shorten the listing (and obscure some filenames)

FileZ has the calls to sscanf

[mg@localhost build]$ make
[CC ../app/file1.c]
[CC ../app/file2.c]
[CC ../app/fileX.c]
/tmp/cc1W9Z2h.s: Assembler messages:
/tmp/cc1W9Z2h.s:15: Warning: ignoring changed section attributes for .data
[CC ../app/fileY.c]
[CC ../app/new_dir/fileZ.c]

[LD host_app]
/home/mg/bin/gcc-arm-none-eabi-6-2017-q1-update/bin/../lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/bin/ld: mode armelf
/tmp/cc7kOq12.ltrans7.ltrans.o: In function `GetCharField':
/home/mg/dev/Ing/rac_mike_min/build/../app/new_dir/fileZ.c:303: undefined reference to `sscanf'
/home/mg/dev/Ing/rac_mike_min/build/../app/new_dir/fileZ.c:303: undefined reference to `sscanf'
/tmp/cc7kOq12.ltrans7.ltrans.o: In function `GetIntField':
/home/mg/dev/Ing/rac_mike_min/build/../app/new_dir/fileZ.c:334: undefined reference to `sscanf'
/home/mg/bin/gcc-arm-none-eabi-6-2017-q1-update/bin/../lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/bin/ld: link errors found, deleting executable `gcc_host_app/Exe/host_app.elf'
collect2: error: ld returned 1 exit status recipe for target 'gcc_host_app/Exe/host_app.bin' failed
make: *** [gcc_host_app/Exe/host_app.bin] Error 1
[mg@localhost build]$

So there's no line with libc.a or libgcc.a? I see that you are doing a LTO link, that probably has something to do with your error. Can you try to link and/or compile without LTO to check if you still have the error?

Best regards.

Mike Gilmer (mike65535) said : #6

>>So there's no line with libc.a or libgcc.a?
In the past I've added -L<my lib directory> and -lc - doing so had no effect.
Also, as I said, the linker is finding memset so not sure the -L or -l matters?

>>doing a LTO link
I don't understand -would you clarify please?

Mike Gilmer (mike65535) said : #7

OK, I removed the -flto in the CFLAGS and LDFLAGS and nothing changed.

Hi Mike,

Is the output with -Wl,--trace changed without LTO? Could you provide the output of -print-multi-directory with the same options you used during link?

Thanks in advance.

Mike Gilmer (mike65535) said : #9

>>Is the output with -Wl,--trace changed without LTO
The only difference is the missing "/tmp/cc7kOq12.ltrans0.ltrans.o" lines
All the indications of "undefined reference to `sscanf' " are still there

Being new to this I had to hack around to get this to work. I assume you mean to add
-print-multi-directory to CFLAGS? That was the only the build completed (well, almost completed)

(Your original post - post #3 - for this command had it with double hyphens: --print-multi-directory so maybe I'm using it wrong)

The only change to the output was the addition of
thumb/v7e-m (twice) after each .c file listing


Launchpad Janitor (janitor) said : #10

This question was expired because it remained in the 'Open' state without activity for the last 15 days.