Author Topic: Copying DLL's to Release folder?  (Read 7839 times)

Offline Lowkus

  • Multiple posting newcomer
  • *
  • Posts: 14
Copying DLL's to Release folder?
« on: May 08, 2016, 05:40:45 am »
I'm new to C++ and CodeBlocks... is there an easy way to automatically copy all the dependent DLL's into the exe release folder?  Currently I'm hunting down and copying them manually.  I'm compiling on Win7 x64, if that matters.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Copying DLL's to Release folder?
« Reply #1 on: May 08, 2016, 12:04:44 pm »
You can write a post build step script to do it.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Lowkus

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: Copying DLL's to Release folder?
« Reply #2 on: May 10, 2016, 09:07:13 am »
Is it a simple script that automatically copies all dependent DLL's to the target destination?  Or do I have to manually find all the DLL's and write them line-by-line into the script, updating the script manually whenever the dependencies change over the course of development?

I was hoping to avoid manually writing a script.  So far what I've scripted (below) throws an "execution fails" error.

IO.CopyFile(_"$(#wx.lib)\gcc_dll\wxmsw310u_gcc_cb.dll", _"$(PROJECT_DIR)$(TARGET_OUTPUT_DIR)wxmsw310u_gcc_cb.dll", true)

Execution of 'IO.CopyFile(_"C:\wxWidgets-3.1.0\lib\gcc_dll\wxmsw310u_gcc_cb.dll", _"C:\cProjects\AppTest\bin\Release\wxmsw310u_gcc_cb.dll", true)' in 'C:\cProjects\AppTest' failed.
« Last Edit: May 10, 2016, 09:10:19 am by Lowkus »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Copying DLL's to Release folder?
« Reply #3 on: May 10, 2016, 12:00:02 pm »
There is nothing automatic. You have to find the list and write copy commands for everything you need.

Are you sure that _"blbabla" is valid syntax? I think it should be _("blabla").
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Copying DLL's to Release folder?
« Reply #4 on: May 10, 2016, 03:57:02 pm »
You could munge the output of a dependency checker, but you only want stuff that isn't already present on a clean system

http://stackoverflow.com/questions/7378959/how-to-check-for-dll-dependency

Offline Lowkus

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: Copying DLL's to Release folder?
« Reply #5 on: May 30, 2016, 10:40:59 am »
I added the parenthesis but still no luck.

IO.CopyFile(_("$(#wx.lib)\gcc_dll\wxmsw310u_gcc_cb.dll"), _("$(PROJECT_DIR)$(TARGET_OUTPUT_DIR)wxmsw310u_gcc_cb.dll"), true)

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Copying DLL's to Release folder?
« Reply #6 on: May 30, 2016, 02:16:58 pm »
any error message?

Offline Lowkus

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: Copying DLL's to Release folder?
« Reply #7 on: June 05, 2016, 10:38:39 pm »
Same error message as before, with slight variation.

Execution of 'IO.CopyFile(_("C:\wxWidgets-3.1.0\lib\gcc_dll\wxmsw310u_gcc_cb.dll"), _("C:\Users\Mark\Documents\cProjects\AppTest\bin\Debug\wxmsw310u_gcc_cb.dll"), true)' in 'C:\Users\Mark\Documents\cProjects\AppTest' failed.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Copying DLL's to Release folder?
« Reply #8 on: June 06, 2016, 01:33:32 pm »
1) You need to escape (replace)  the '\' character with "\\"
2) You have to use the function "ReplaceMacros()" for expanding $(TARGET_OUTPUT_DIR) ecc.

not tested:
Code
IO.CopyFile(ReplaceMacros(_("$(#wx.lib)\\gcc_dll\\wxmsw310u_gcc_cb.dll")),ReplaceMacros( _("$(PROJECT_DIR)$(TARGET_OUTPUT_DIR)wxmsw310u_gcc_cb.dll")), true)

greetings

Offline Aaron

  • Multiple posting newcomer
  • *
  • Posts: 59
Re: Copying DLL's to Release folder?
« Reply #9 on: August 01, 2016, 12:07:22 am »
So is the example script given in the 'The Build Process Of Code::Blocks' page here: http://wiki.codeblocks.org/index.php?title=The_build_process_of_Code::Blocks be valid syntax ?

It produces the below attached error. (When tested with the 'Vallidate all attached scripts' button, and during build)

Script example given:
Code
cmd /c copy "$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)" "C:\Program\bin"

I added the 'expected end of statement ";", but the error was the same.

I am working toward a script to copy the wxmsw30u_gcc_custom.dll to my current project's Release folder.

Like this:
Code
cmd /c copy "$(#wx.lib)\\gcc_dll\\wxmsw30u_gcc_custom.dll" "$(PROJECT_DIR)" 
or this:
Code
cmd /c copy "$(#wx.lib)\gcc_dll\wxmsw30u_gcc_custom.dll" "$(PROJECT_DIR)";

Both of my scripts produce same error.

I'm not finding separate places for Pre-Build or Post-Build scripts, that I have read references to.
I'm placing it in: Project properties, Build scripts tab, Release, Attached build scripts (file loc path).

Advice appreciated.



« Last Edit: August 01, 2016, 01:14:04 am by Aaron »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Copying DLL's to Release folder?
« Reply #10 on: August 01, 2016, 01:23:38 am »
Aaron:

Are trying to do an script or a shell command?
They are not the same thing.

Edit1 below:
What you posted was a windows command AKA "shell command".
What was posted right before you was a Code::Blocks script command.

Tim S.
« Last Edit: August 01, 2016, 01:28:00 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Aaron

  • Multiple posting newcomer
  • *
  • Posts: 59
Re: Copying DLL's to Release folder?
« Reply #11 on: August 01, 2016, 01:34:34 am »
Well it started as a script, trying to use ObFuscated & BlueHazzard's advice to the poster of this question. Above.

But if a shell command would accomplish what I need terrific.

It would be nice to store this command in Code:Blocks, so that each new project would follow it.

Edit:  Just saw your edit, I have to learn a bit more about this.  Basing my query mainly about the Code::Blocks page script I can't get to work(without errors).
« Last Edit: August 01, 2016, 01:38:51 am by Aaron »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Copying DLL's to Release folder?
« Reply #12 on: August 01, 2016, 02:44:27 am »
You posted something that IS NOT Code::Blocks script!!

Try adding it in the post/after command and STOP trying to use it as a script!!

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Aaron

  • Multiple posting newcomer
  • *
  • Posts: 59
Re: Copying DLL's to Release folder?
« Reply #13 on: August 01, 2016, 04:41:01 am »
Thanks Tim.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Copying DLL's to Release folder?
« Reply #14 on: August 01, 2016, 11:59:16 am »
Hi, a few suggestions and explanations from my side:

To your approach of the problem to copy the dll:
1) I would not recommend to copy the dll on every time you build your project... This are several MByte and unnecessary... So the Pre and Post build steps from the Build options are not the best way...
2) There are two possibilities left:
    a) Use a Tool menu entry, so you have to manually call this tool one time you create the project
    b) Modify the wizard script so it copies the dll at the time it is creating the project

To your confusion with the script thing:
In cb are generally two types of possibilities to automate things:
   a) Use the normal CMD or shell commands. You can use this if you don't share this project across multiple platforms like windows linux mac...
   b) Use the cb integrated squirrel script engine. This is a platform Independent approach. Use this if you share your project between machines..
       (or c) a combination of the two things)

When i write something like this:
Code
IO.CopyFile(ReplaceMacros(_("$(#wx.lib)\\gcc_dll\\wxmsw310u_gcc_cb.dll")),ReplaceMacros( _("$(PROJECT_DIR)$(TARGET_OUTPUT_DIR)wxmsw310u_gcc_cb.dll")), true)
i mean a squirrel code. This has to be embedded in "[[]]" parenthesis so cb recognize them as squirrel script. So if you use this script in the pre/post build steps it would look like this:
Code
[[IO.CopyFile(ReplaceMacros(_("$(#wx.lib)\\gcc_dll\\wxmsw310u_gcc_cb.dll")),ReplaceMacros( _("$(PROJECT_DIR)$(TARGET_OUTPUT_DIR)wxmsw310u_gcc_cb.dll")), true)]]
If you want to use the normal cmd or shell commands like this:
Code
cmd /c copy "$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)" "C:\Program\bin"
you post this in the pre/post build steps like this (note: no ""[[]]":
Code
cmd /c copy "$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)" "C:\Program\bin"
cb will then replace all your variables (starting with $( )) and execute the command

This should clear things up. Now to your question:
If you want to copy the dll every time you build the target (not my recommendation) you put either of the two script lines in
Project->Build Options-> Select the top most target on the left->Pre/post build Steps

If you want to create a Tool entry:
Tools+->Configure Tools->New
Enter a Tool name like, "Copy wx dll"
As command line you can enter one of the two scripts i posted above (here i would recommend the cmd approach)
Now every time you call Tools+->Copy wx dll your dll gets copied in the current target output directorie

Modifying the script wizard is a bit more complicated, and i don't have the time to write it down now... You can ask me in 10 days again ;). But maybe someone else can help you with this...

greetings