Author Topic: [Help needed] Setting Visual Studio Linker Flags in C++ Code::Blocks Project  (Read 778 times)

Offline Grashek

  • Single posting newcomer
  • *
  • Posts: 3
Hello C::B Community,

I have been using C::B for quite a while now.
Recently I have been asked to recompile my projects with the following linker flags (security compliance reasons):

/DYNAMICBASE
/NXCOMPAT
/GS
/SAFESEH


I have been using the GNU GCC Compiler using -std=c++11
I attached my compiler settings as PNG picture.


Now my question is:
How can I recompile my projects using these linker settings?

Could you guide me how to do it within Code::Blocks or within terminal please.


Thank you

~~Grashek


P.S.: I ran multiple google search queuries for hours and did not find any solution to my problem.


Offline sodev

  • Regular
  • ***
  • Posts: 405
These are MSVC linker flags, they can't be used for GCC (directly). Not sure if you should quickly switch to MSVC or tell your compliance department that you are using GCC ;D.

Anyway for the first two flags there are equivalent GCC switches, these are -Wl,--dynamicbase and -Wl,--nxcompat, you set these as Other linker options in CodeBlocks, either in the project specific settings or global compiler settings. The other two are more tricky. According to the docs /SAFESEH only applies to x86 builds and afaik GCC on windows supports SEH only in x86_64 builds so this flag does not apply to you. For the /GS flag you have to search if GCC supports something similar and how to enable it.

Offline Grashek

  • Single posting newcomer
  • *
  • Posts: 3
Thank you @sodev These were good pointers. May I ask a follow-up question please.

I attached another image showing the following compiler error now:

Quote
ld.exe||cannot find dynamicbase: No such file or directory|
ld.exe||cannot find nxcompat: No such file or directory|
||error: ld returned 1 exit status|
||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 3 second(s)) ===|

My understanding is, that I need to be able to tell Code::Blocks where the library is,
that allows to linker to understand what it should be doing.

Now where can I get these libraries?
Where can I download them?


Offline Grashek

  • Single posting newcomer
  • *
  • Posts: 3
With the linker flag " -L " I got rid of the error in regards to DYNAMICBASE. (ref: https://sourceware.org/binutils/docs/ld/Options.html)

However I still get the error for nxcompat:
Quote
ld.exe||cannot find nxcompat: No such file or directory|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7013
    • My Best Post
Those are linker options! They are not linker libraries.

You likely need to enter them in the extra or other linker settings.

Tim S.
« Last Edit: June 09, 2020, 06:20:49 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7013
    • My Best Post
The options in GCC that might be similar to "GS".

fstack-security-check  Edit: "could not find docs on this it might be an old option that was removed"
fstack-protector

Edit add link https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html

Tim S.


« Last Edit: June 10, 2020, 02:33:47 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org