Author Topic: How to make .dll build with .def file in cb?  (Read 5783 times)

Offline manceb

  • Single posting newcomer
  • *
  • Posts: 5
How to make .dll build with .def file in cb?
« on: December 22, 2014, 10:12:42 am »
I'm the new one in cb from vs2010.The cb svn I have been using is 10050.Everything is fine except I can't use .def file to define a .dll file.
I have read all of the topics carefully about this problem,such as (http://forums.codeblocks.org/index.php/topic,14812.msg99253.html#msg99253
http://forums.codeblocks.org/index.php/topic,10559.msg72397.html#msg72397
http://forums.codeblocks.org/index.php/topic,14285.msg96045.html#msg96045
http://forums.codeblocks.org/index.php/topic,8236.msg61186.html#msg61186
http://forums.codeblocks.org/index.php/topic,8967.msg64716.html#msg64716
http://forums.codeblocks.org/index.php/topic,10882.msg74368.html#msg74368
http://forums.codeblocks.org/index.php/topic,2616.msg20703.html#msg20703
).But they did not solve my problem.so thanks to someone to tell me  How to configure C::B to use DEF file when creating DLL?
test code :
main.cpp:
Code
int __stdcall Add(int numa, int numb)
{
     return (numa + numb);
}

int __stdcall Sub(int numa, int numb)
{
     return (numa - numb);
}

main.def
Code

LIBRARY test
EXPORTS
Add @ 1
Sub @ 2
the project options




the other linker options and errors.







I'd appreciate any reply

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: How to make .dll build with .def file in cb?
« Reply #1 on: December 22, 2014, 12:19:17 pm »
I'm not familiar with def files, but it is in general better to post the content of the "Build Log" window instead of the "Build messages" window. in Build log are showed more information. And it is also better to post the content in code tags (# symbol in the forum editor), instead of pictures.

And as far as i know, you don't need any .def file with the gcc compiler. You need the .def file only with msvc compiler, but you are using the gcc to compiler your program...

greetings

Offline manceb

  • Single posting newcomer
  • *
  • Posts: 5
Re: How to make .dll build with .def file in cb?
« Reply #2 on: December 23, 2014, 11:40:13 am »
thank you for you replay,the bulid log as follow.


because the dll wich used in some program must use __stdall and .def


as you  see ,so can anyone help me to use cb to create the dll with .def file?

thank you.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: How to make .dll build with .def file in cb?
« Reply #3 on: December 23, 2014, 12:08:10 pm »
As you can clearly see in the output the option "--def" is not supported by gcc...

are you ever planing to go back to msvc?
if not, why are you using def files and not simply use "__declspec(dllexport)" in your source? (http://stackoverflow.com/a/21902439)

i don't know any option for gcc to use def files, and this is also no gcc support forum. It is a c::b support forum, so if you find a option to use def files with gcc and want to know how to use it with c::b then we can help you better...

PS.: i searched a bit and according some sites you need to use a thirparty tool to use def files with gcc: http://www.boyunjian.com/do/article/snapshot.do?uid=1013034473452214461
so you need a post build step to make your dlls. You can make a post build step in Project->Build Options ->Pre/Post build steps->Post build step.
The Variables you can use in this post build steps are described here: http://wiki.codeblocks.org/index.php?title=Variable_expansion
so you need a postbuild line like this (no waranty, i can't test it, because no windows, and also not a expert with this kind of sorcery )
Code
dllwrap -o $(TARGET_OUTPUT_BASENAME).dll --driver-name c++ --def DEF_FILE $(TARGET_OBJECT_DIR)\$(TARGET_OUTPUT_BASENAME).o $(TARGET_OUTPUT_FILE) -Wl,--enable-stdcall-fixup
« Last Edit: December 23, 2014, 12:10:06 pm by BlueHazzard »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: How to make .dll build with .def file in cb?
« Reply #4 on: December 23, 2014, 10:38:42 pm »
Edit: Looks like my post is NOT needed by OP; I should have read the whole thread before posting.
Creating the def was NOT the problem; using it was. I never used one because most of the time it is never needed.


IIRC, def is in the Project -> Property menu.

Tab: "Build Targets"
Under "selected build target options"
Type: Needs set to an option that support .def file. DLL does.
Checkmark: Create def export file.
Adjust "Def. file filename"

Tim S.
« Last Edit: December 23, 2014, 10:46:48 pm 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 manceb

  • Single posting newcomer
  • *
  • Posts: 5
Re: How to make .dll build with .def file in cb?
« Reply #5 on: January 22, 2015, 07:51:39 am »
dllwrap -o $(TARGET_OUTPUT_BASENAME).dll $(TARGET_OBJECT_DIR)$(TARGET_OUTPUT_BASENAME).o  --def $(TARGET_OUTPUT_BASENAME).def  --output-lib lib$(TARGET_OUTPUT_BASENAME).a  -Wl,--enable-stdcall-fixup
this coulde be work well.