Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

ICPC read linker commands from file

Mario_K_
Beginner
905 Views

Hello,

I want to read linker commands from a file by the option -T but there is a syntax error

ld:linkerCommands:1: syntax error

Called command is: icpc ... -TlinkerCommands

Where the file "linkerCommands" has the content "-L/myPath/" (only one line)

Do I need a special syntax in the file? Is it possible to write more then one command to the file?

Thank you very much.

icpc version 16.0.0 under RedHat 7.1

 

0 Kudos
7 Replies
Judith_W_Intel
Employee
905 Views

 

If you look in the GNU ld documentation here:

https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_3.html#SEC3

You'll see the following description of the -T option:

-T commandfile
 
--script=commandfile
Read link commands from the file commandfile. These commands replace ld's default link script (rather than adding to it), so commandfile must specify everything necessary to describe the target format. You must use this option if you want to use a command which can only appear once in a linker script, such as the SECTIONS or MEMORY command. See section Command Language. If commandfile does not exist, ld looks for it in the directories specified by any preceding `-L' options. Multiple `-T' options accumulate.

 

So

(1) The -T option needs to be a complete replacement for all linker options

(2) The syntax needs to use the special Command Language described here:

https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_5.html#SEC5

 

 
 

 

0 Kudos
Kittur_G_Intel
Employee
905 Views

Thanks Judy, that makes sense and I did try out as well. It had to conform to what you indicated, appreciate much.

Kittur

0 Kudos
Kevin_D_Intel
Employee
905 Views

The GNU ld @<file> option can be used to augment the linker options.

@file
    Read command-line options from file.  The options read are inserted
    in place of the original @file option.  If file does not exist, or
    cannot be read, then the option will be treated literally, and not
    removed.

    Options in file are separated by whitespace.  A whitespace
    character may be included in an option by surrounding the entire
    option in either single or double quotes.  Any character (including
    a backslash) may be included by prefixing the character to be
    included with a backslash.  The file may itself contain additional
    @file options; any such options will be processed recursively.

For example:

$ cat h.cpp
#include <iostream>

int main() {
 std::cout << "Testing...." << std::endl;
 return 0;
}

$ cat h.lds
-V -L./mypath

$ icpc -Wl,@h.lds h.cpp
GNU ld version 2.23.52.0.1-55.el7 20130226
  Supported emulations:
   elf_x86_64
   elf32_x86_64
   elf_i386
   i386linux
   elf_l1om
   elf_k1om

 

0 Kudos
Kittur_G_Intel
Employee
905 Views

That's correct, thx for pointing that out as well Kevin.

Kittur

0 Kudos
Mario_K_
Beginner
905 Views

Thank you very much for these very helpful comments. The "@file" option is exactly what I've searched.

0 Kudos
Kevin_D_Intel
Employee
905 Views

You're welcome. Glad to hear that.

0 Kudos
Kittur_G_Intel
Employee
905 Views

Likewise, glad to hear it's resolved!

Kittur

0 Kudos
Reply