更改freeBasic编写dll中函数名被大写和尾部带的@数字
freeBasic编译是基于gas或gcc的,换句话说freeBasic先是预编译,然后交给 gcc 编译,再交给 ld 链接。
freeBasic可以使用C/C++的.h文件和lib库,但必须重写为freeBasic的bi格式,避免关键词重叠等问题,这是C/C++不同的(还有类等的不同)。
freeBasic中Add_Number函数,编译dll后可能变为 ADD_NUMBER@4 ,这在java JNA中调用会遇到麻烦。
- 用cdecl方式,编译出的dll会保持原样,没有@数字。
点击查看代码
function fb_add cdecl(byval a as integer, byval b as integer) as integer export
return a + b
end function
点击查看代码
extern "C"
function fb_add (byval a as integer, byval b as integer) as integer export
return a + b
end function
end extern
- 用windows-ms方式编译出的标准dll也会保持原样,没@数字
点击查看代码
extern "windows-ms"
function fb_add (byval a as integer, byval b as integer) as integer export
return a + b
end function
end extern
- 用alias编译标准dll时会保持函数名不变,但尾部有@数字
点击查看代码
function fb_add alias fb_add (byval a as integer, byval b as integer) as integer export
return a + b
end function
- 在链接时去掉尾数字,编译输出 -dll,选backend编译器 -gen gcc,向编译器输出参数 -Wc -O3,向链接器输出参数 -Wl --kill-at
4.1 gcc 可选参数
点击查看代码
C:\Users\Administrator>gcc --help
Usage: gcc [options] file...
Options:
-pass-exit-codes Exit with highest error code from a phase.
--help Display this information.
--target-help Display target specific command line options (including assembler and linker options).
--help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...].
Display specific types of command line options.
(Use '-v --help' to display command line options of sub-processes).
--version Display compiler version information.
-dumpspecs Display all of the built in spec strings.
-dumpversion Display the version of the compiler.
-dumpmachine Display the compiler's target processor.
-foffload=<targets> Specify offloading targets.
-print-search-dirs Display the directories in the compiler's search path.
-print-libgcc-file-name Display the name of the compiler's companion library.
-print-file-name=<lib> Display the full path to library <lib>.
-print-prog-name=<prog> Display the full path to compiler component <prog>.
-print-multiarch Display the target's normalized GNU triplet, used as
a component in the library path.
-print-multi-directory Display the root directory for versions of libgcc.
-print-multi-lib Display the mapping between command line options and
multiple library search directories.
-print-multi-os-directory Display the relative path to OS libraries.
-print-sysroot Display the target libraries directory.
-print-sysroot-headers-suffix Display the sysroot suffix used to find headers.
-Wa,<options> Pass comma-separated <options> on to the assembler.
-Wp,<options> Pass comma-separated <options> on to the preprocessor.
-Wl,<options> Pass comma-separated <options> on to the linker.
-Xassembler <arg> Pass <arg> on to the assembler.
-Xpreprocessor <arg> Pass <arg> on to the preprocessor.
-Xlinker <arg> Pass <arg> on to the linker.
-save-temps Do not delete intermediate files.
-save-temps=<arg> Do not delete intermediate files.
-no-canonical-prefixes Do not canonicalize paths when building relative
prefixes to other gcc components.
-pipe Use pipes rather than intermediate files.
-time Time the execution of each subprocess.
-specs=<file> Override built-in specs with the contents of <file>.
-std=<standard> Assume that the input sources are for <standard>.
--sysroot=<directory> Use <directory> as the root directory for headers
and libraries.
-B <directory> Add <directory> to the compiler's search paths.
-v Display the programs invoked by the compiler.
-### Like -v but options quoted and commands not executed.
-E Preprocess only; do not compile, assemble or link.
-S Compile only; do not assemble or link.
-c Compile and assemble, but do not link.
-o <file> Place the output into <file>.
-pie Create a dynamically linked position independent
executable.
-shared Create a shared library.
-x <language> Specify the language of the following input files.
Permissible languages include: c c++ assembler none
'none' means revert to the default behavior of
guessing the language based on the file's extension.
Options starting with -g, -f, -m, -O, -W, or --param are automatically
passed on to the various sub-processes invoked by gcc. In order to pass
other options on to these processes the -W<letter> options must be used.
For bug reporting instructions, please see:
<https://gcc.gnu.org/bugs/>.
点击查看代码
Usage: ld [options] file...
Options:
-a KEYWORD Shared library control for HP/UX compatibility
-A ARCH, --architecture ARCH
Set architecture
-b TARGET, --format TARGET Specify target for following input files
-c FILE, --mri-script FILE Read MRI format linker script
-d, -dc, -dp Force common symbols to be defined
--dependency-file FILE Write dependency file
--force-group-allocation Force group members out of groups
-e ADDRESS, --entry ADDRESS Set start address
-E, --export-dynamic Export all dynamic symbols
--no-export-dynamic Undo the effect of --export-dynamic
--enable-non-contiguous-regions
Enable support of non-contiguous memory regions
--enable-non-contiguous-regions-warnings
Enable warnings when --enable-non-contiguous-regions may cause unexpected behaviour
--disable-linker-version Disable the LINKER_VERSION linker script directive
--enable-linker-version Enable the LINKER_VERSION linker script directive
-EB Link big-endian objects
-EL Link little-endian objects
-f SHLIB, --auxiliary SHLIB Auxiliary filter for shared object symbol table
-F SHLIB, --filter SHLIB Filter for shared object symbol table
-g Ignored
-G SIZE, --gpsize SIZE Small data size (if no size, same as --shared)
-h FILENAME, -soname FILENAME
Set internal name of shared library
-I PROGRAM, --dynamic-linker PROGRAM
Set PROGRAM as the dynamic linker to use
--no-dynamic-linker Produce an executable with no program interpreter header
-l LIBNAME, --library LIBNAME
Search for library LIBNAME
-L DIRECTORY, --library-path DIRECTORY
Add DIRECTORY to library search path
--sysroot=<DIRECTORY> Override the default sysroot location
-m EMULATION Set emulation
-M, --print-map Print map file on standard output
-n, --nmagic Do not page align data
-N, --omagic Do not page align data, do not make text readonly
--no-omagic Page align data, make text readonly
-o FILE, --output FILE Set output file name
-O Optimize output file
--out-implib FILE Generate import library
-plugin PLUGIN Load named plugin
-plugin-opt ARG Send arg to last-loaded plugin
-plugin-save-temps Store plugin intermediate files permanently
-flto Ignored for GCC LTO option compatibility
-flto-partition= Ignored for GCC LTO option compatibility
-fuse-ld= Ignored for GCC linker option compatibility
--map-whole-files Ignored for gold option compatibility
--no-map-whole-files Ignored for gold option compatibility
-Qy Ignored for SVR4 compatibility
-q, --emit-relocs Generate relocations in final output
-r, -i, --relocatable Generate relocatable output
-R FILE, --just-symbols FILE
Just link symbols (if directory, same as --rpath)
--remap-inputs-file FILE Provide a FILE containing input remapings
--remap-inputs PATTERN=FILE Remap input files matching PATTERN to FILE
-s, --strip-all Strip all symbols
-S, --strip-debug Strip debugging symbols
--strip-discarded Strip symbols in discarded sections
--no-strip-discarded Do not strip symbols in discarded sections
-t, --trace Trace file opens
-T FILE, --script FILE Read linker script
--default-script FILE, -dT Read default linker script
-u SYMBOL, --undefined SYMBOL
Start with undefined reference to SYMBOL
--require-defined SYMBOL Require SYMBOL be defined in the final output
--unique [=SECTION] Don't merge input [SECTION | orphan] sections
-Ur Build global constructor/destructor tables
-v, --version Print version information
-V Print version and emulation information
-x, --discard-all Discard all local symbols
-X, --discard-locals Discard temporary local symbols (default)
--discard-none Don't discard any local symbols
-y SYMBOL, --trace-symbol SYMBOL
Trace mentions of SYMBOL
-Y PATH Default search path for Solaris compatibility
-(, --start-group Start a group
-), --end-group End a group
--accept-unknown-input-arch Accept input files whose architecture cannot be determined
--no-accept-unknown-input-arch
Reject input files whose architecture is unknown
--as-needed Only set DT_NEEDED for following dynamic libs if used
--no-as-needed Always set DT_NEEDED for dynamic libraries mentioned on
the command line
-assert KEYWORD Ignored for SunOS compatibility
-Bdynamic, -dy, -call_shared
Link against shared libraries
-Bstatic, -dn, -non_shared, -static
Do not link against shared libraries
-Bno-symbolic Don't bind global references locally
-Bsymbolic Bind global references locally
-Bsymbolic-functions Bind global function references locally
--check-sections Check section addresses for overlaps (default)
--no-check-sections Do not check section addresses for overlaps
--copy-dt-needed-entries Copy DT_NEEDED links mentioned inside DSOs that follow
--no-copy-dt-needed-entries Do not copy DT_NEEDED links mentioned inside DSOs that follow
--cref Output cross reference table
--defsym SYMBOL=EXPRESSION Define a symbol
--demangle [=STYLE] Demangle symbol names [using STYLE]
--disable-multiple-abs-defs Do not allow multiple definitions with symbols included
in filename invoked by -R or --just-symbols
--embedded-relocs Generate embedded relocs
--fatal-warnings Treat warnings as errors
--no-fatal-warnings Do not treat warnings as errors (default)
-fini SYMBOL Call SYMBOL at unload-time
--force-exe-suffix Force generation of file with .exe suffix
--gc-sections Remove unused sections (on some targets)
--no-gc-sections Don't remove unused sections (default)
--print-gc-sections List removed unused sections on stderr
--no-print-gc-sections Do not list removed unused sections
--gc-keep-exported Keep exported symbols when removing unused sections
--hash-size=<NUMBER> Set default hash table size close to <NUMBER>
--help Print option help
-init SYMBOL Call SYMBOL at load-time
-Map FILE/DIR Write a linker map to FILE or DIR/<outputname>.map
--no-define-common Do not define Common storage
--no-demangle Do not demangle symbol names
--no-keep-memory Use less memory and more disk I/O
--no-undefined Do not allow unresolved references in object files
-w, --no-warnings Do not display any warning or error messages
--allow-shlib-undefined Allow unresolved references in shared libraries
--no-allow-shlib-undefined Do not allow unresolved references in shared libs
--allow-multiple-definition Allow multiple definitions
--error-handling-script SCRIPT
Provide a script to help with undefined symbol errors
--undefined-version Allow undefined version
--no-undefined-version Disallow undefined version
--default-symver Create default symbol version
--default-imported-symver Create default symbol version for imported symbols
--no-warn-mismatch Don't warn about mismatched input files
--no-warn-search-mismatch Don't warn on finding an incompatible library
--no-whole-archive Turn off --whole-archive
--noinhibit-exec Create an output file even if errors occur
-nostdlib Only use library directories specified on
the command line
--oformat TARGET Specify target of output file
--print-output-format Print default output format
--print-sysroot Print current sysroot
-qmagic Ignored for Linux compatibility
--reduce-memory-overheads Reduce memory overheads, possibly taking much longer
--max-cache-size=SIZE Set the maximum cache size to SIZE bytes
--relax Reduce code size by using target specific optimizations
--no-relax Do not use relaxation techniques to reduce code size
--retain-symbols-file FILE Keep only symbols listed in FILE
-rpath PATH Set runtime shared library search path
-rpath-link PATH Set link time shared library search path
-shared, -Bshareable Create a shared library
-pie, --pic-executable Create a position independent executable
-no-pie Create a position dependent executable (default)
--sort-common [=ascending|descending]
Sort common symbols by alignment [in specified order]
--sort-section name|alignment
Sort sections by name or maximum alignment
--section-ordering-file FILE
Sort sections by statements in FILE
--spare-dynamic-tags COUNT How many tags to reserve in .dynamic section
--split-by-file [=SIZE] Split output sections every SIZE octets
--split-by-reloc [=COUNT] Split output sections every COUNT relocs
--stats Print resource usage statistics
--no-stats Do not print resource usage statistics
--target-help Display target specific options
--task-link SYMBOL Do task level linking
--traditional-format Use same format as native linker
--section-start SECTION=ADDRESS
Set address of named section
--image-base ADDRESS Set image base address
-Tbss ADDRESS Set address of .bss section
-Tdata ADDRESS Set address of .data section
-Ttext ADDRESS Set address of .text section
-Ttext-segment ADDRESS Set address of text segment
-Trodata-segment ADDRESS Set address of rodata segment
-Tldata-segment ADDRESS Set address of ldata segment
--unresolved-symbols=<method>
How to handle unresolved symbols. <method> is:
ignore-all, report-all, ignore-in-object-files,
ignore-in-shared-libs
--verbose [=NUMBER] Output lots of information during link
--version-script FILE Read version information script
--version-exports-section SYMBOL
Take export symbols list from .exports, using
SYMBOL as the version.
--dynamic-list-data Add data symbols to dynamic list
--dynamic-list-cpp-new Use C++ operator new/delete dynamic list
--dynamic-list-cpp-typeinfo Use C++ typeinfo dynamic list
--dynamic-list FILE Read dynamic list
--export-dynamic-symbol SYMBOL
Export the specified symbol
--export-dynamic-symbol-list FILE
Read export dynamic symbol list
--warn-common Warn about duplicate common symbols
--warn-constructors, --error-execstack, --no-error-execstack, --warn-execstack-objects, --warn-execstack, --no-warn-execstack, --error-rwx-segments, --no-error-rwx-segments, --warn-rwx-segments, --no-warn-rwx-segments
Warn if global constructors/destructors are seen
--warn-multiple-gp Warn if the multiple GP values are used
--warn-once Warn only once per undefined symbol
--warn-section-align Warn if start of section changes due to alignment
--warn-textrel Warn if output has DT_TEXTREL
--warn-alternate-em Warn if an object has alternate ELF machine code
--warn-unresolved-symbols Report unresolved symbols as warnings
--error-unresolved-symbols Report unresolved symbols as errors
--whole-archive Include all objects from following archives
--wrap SYMBOL Use wrapper functions for SYMBOL
--ignore-unresolved-symbol SYMBOL
Unresolved SYMBOL will not cause an error or warning
--push-state Push state of flags governing input file handling
--pop-state Pop state of flags governing input file handling
--print-memory-usage Report target memory usage
--orphan-handling =MODE Control how orphan sections are handled.
--print-map-discarded Show discarded sections in map file output (default)
--no-print-map-discarded Do not show discarded sections in map file output
--print-map-locals Show local symbols in map file output
--no-print-map-locals Do not show local symbols in map file output (default)
--ctf-variables Emit names and types of static variables in CTF
--no-ctf-variables Do not emit names and types of static variables in CTF
--ctf-share-types=<method> How to share CTF types between translation units.
<method> is: share-unconflicted (default),
share-duplicated
@FILE Read options from FILE
ld: supported targets: pe-x86-64 pei-x86-64 pe-bigobj-x86-64 elf64-x86-64 pe-i386 pei-i386 elf32-i386 elf32-iamcu pdb elf64-little elf64-big elf32-little elf32-big srec symbolsrec verilog tekhex binary ihex plugin
ld: supported emulations: i386pep i386pe
ld: emulation specific options:
i386pep:
--base_file <basefile> Generate a base file for relocatable DLLs
--dll Set image base to the default for DLLs
--file-alignment <size> Set file alignment
--heap <size> Set initial size of the heap
--image-base <address> Set start address of the executable
--major-image-version <number> Set version number of the executable
--major-os-version <number> Set minimum required OS version
--major-subsystem-version <number> Set minimum required OS subsystem version
--minor-image-version <number> Set revision number of the executable
--minor-os-version <number> Set minimum required OS revision
--minor-subsystem-version <number> Set minimum required OS subsystem revision
--section-alignment <size> Set section alignment
--stack <size> Set size of the initial stack
--subsystem <name>[:<version>] Set required OS subsystem [& version]
--support-old-code Support interworking with old code
--[no-]leading-underscore Set explicit symbol underscore prefix mode
--[no-]insert-timestamp Use a real timestamp rather than zero (default)
This makes binaries non-deterministic
--add-stdcall-alias Export symbols with and without @nn
--disable-stdcall-fixup Don't link _sym to _sym@nn
--enable-stdcall-fixup Link _sym to _sym@nn without warnings
--exclude-symbols sym,sym,... Exclude symbols from automatic export
--exclude-all-symbols Exclude all symbols from automatic export
--exclude-libs lib,lib,... Exclude libraries from automatic export
--exclude-modules-for-implib mod,mod,...
Exclude objects, archive members from auto
export, place into import library instead
--export-all-symbols Automatically export all globals to DLL
--kill-at Remove @nn from exported symbols
--output-def <file> Generate a .DEF file for the built DLL
--warn-duplicate-exports Warn about duplicate exports
--compat-implib Create backward compatible import libs;
create __imp_<SYMBOL> as well
--enable-auto-image-base Automatically choose image base for DLLs
unless user specifies one
--disable-auto-image-base Do not auto-choose image base (default)
--dll-search-prefix=<string> When linking dynamically to a dll without
an importlib, use <string><basename>.dll
in preference to lib<basename>.dll
--enable-auto-import Do sophisticated linking of _sym to
__imp_sym for DATA references
--disable-auto-import Do not auto-import DATA items from DLLs
--enable-runtime-pseudo-reloc Work around auto-import limitations by
adding pseudo-relocations resolved at
runtime
--disable-runtime-pseudo-reloc Do not add runtime pseudo-relocations for
auto-imported DATA
--enable-extra-pep-debug Enable verbose debug output when building
or linking to DLLs (esp. auto-import)
--enable-long-section-names Use long COFF section names even in
executable image files
--disable-long-section-names Never use long COFF section names, even
in object files
--[disable-]high-entropy-va Image is compatible with 64-bit address space
layout randomization (ASLR)
--[disable-]dynamicbase Image base address may be relocated using
address space layout randomization (ASLR)
--enable-reloc-section Create the base relocation table
--disable-reloc-section Do not create the base relocation table
--[disable-]forceinteg Code integrity checks are enforced
--[disable-]nxcompat Image is compatible with data execution
prevention
--[disable-]no-isolation Image understands isolation but do not
isolate the image
--[disable-]no-seh Image does not use SEH; no SE handler may
be called in this image
--[disable-]no-bind Do not bind this image
--[disable-]wdmdriver Driver uses the WDM model
--[disable-]tsaware Image is Terminal Server aware
--build-id[=STYLE] Generate build ID
--pdb=[FILENAME] Generate PDB file
i386pe:
--base_file <basefile> Generate a base file for relocatable DLLs
--dll Set image base to the default for DLLs
--file-alignment <size> Set file alignment
--heap <size> Set initial size of the heap
--image-base <address> Set start address of the executable
--major-image-version <number> Set version number of the executable
--major-os-version <number> Set minimum required OS version
--major-subsystem-version <number> Set minimum required OS subsystem version
--minor-image-version <number> Set revision number of the executable
--minor-os-version <number> Set minimum required OS revision
--minor-subsystem-version <number> Set minimum required OS subsystem revision
--section-alignment <size> Set section alignment
--stack <size> Set size of the initial stack
--subsystem <name>[:<version>] Set required OS subsystem [& version]
--support-old-code Support interworking with old code
--[no-]leading-underscore Set explicit symbol underscore prefix mode
--thumb-entry=<symbol> Set the entry point to be Thumb <symbol>
--[no-]insert-timestamp Use a real timestamp rather than zero (default).
This makes binaries non-deterministic
--add-stdcall-alias Export symbols with and without @nn
--disable-stdcall-fixup Don't link _sym to _sym@nn
--enable-stdcall-fixup Link _sym to _sym@nn without warnings
--exclude-symbols sym,sym,... Exclude symbols from automatic export
--exclude-all-symbols Exclude all symbols from automatic export
--exclude-libs lib,lib,... Exclude libraries from automatic export
--exclude-modules-for-implib mod,mod,...
Exclude objects, archive members from auto
export, place into import library instead.
--export-all-symbols Automatically export all globals to DLL
--kill-at Remove @nn from exported symbols
--output-def <file> Generate a .DEF file for the built DLL
--warn-duplicate-exports Warn about duplicate exports
--compat-implib Create backward compatible import libs;
create __imp_<SYMBOL> as well.
--enable-auto-image-base[=<address>] Automatically choose image base for DLLs
(optionally starting with address) unless
specifically set with --image-base
--disable-auto-image-base Do not auto-choose image base. (default)
--dll-search-prefix=<string> When linking dynamically to a dll without
an importlib, use <string><basename>.dll
in preference to lib<basename>.dll
--enable-auto-import Do sophisticated linking of _sym to
__imp_sym for DATA references
--disable-auto-import Do not auto-import DATA items from DLLs
--enable-runtime-pseudo-reloc Work around auto-import limitations by
adding pseudo-relocations resolved at
runtime.
--disable-runtime-pseudo-reloc Do not add runtime pseudo-relocations for
auto-imported DATA.
--enable-extra-pe-debug Enable verbose debug output when building
or linking to DLLs (esp. auto-import)
--large-address-aware Executable supports virtual addresses
greater than 2 gigabytes
--disable-large-address-aware Executable does not support virtual
addresses greater than 2 gigabytes
--enable-long-section-names Use long COFF section names even in
executable image files
--disable-long-section-names Never use long COFF section names, even
in object files
--[disable-]dynamicbase Image base address may be relocated using
address space layout randomization (ASLR)
--enable-reloc-section Create the base relocation table
--disable-reloc-section Do not create the base relocation table
--[disable-]forceinteg Code integrity checks are enforced
--[disable-]nxcompat Image is compatible with data execution
prevention
--[disable-]no-isolation Image understands isolation but do not
isolate the image
--[disable-]no-seh Image does not use SEH. No SE handler may
be called in this image
--[disable-]no-bind Do not bind this image
--[disable-]wdmdriver Driver uses the WDM model
--[disable-]tsaware Image is Terminal Server aware
--build-id[=STYLE] Generate build ID
--pdb=[FILENAME] Generate PDB file
Report bugs to <https://sourceware.org/bugzilla/>

浙公网安备 33010602011771号