www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - DMD Mac and linking with frameworks

reply Jacob Carlborg <doob me.com> writes:
If I understand things correct dmd uses gcc to do the linking on linux 
and osx, therefore I should be able to link against frameworks on osx.

GDC/GCC uses the compiler flag "-framework Carbon" and the passes the 
same flag to the linker. LDC/LLVM uses the linker flag 
"-framework=Carbon" which I can pass to the linker using "-L". But I 
can't figure out how to do that with DMD.

The problem is if compile like this for example: "dmd -L-framework 
Carbon main.d" dmd complains that it can't find Carbon.d. It seems that 
it takes everything as a D source file if it doesn't recognize it as a 
compiler switch.
Mar 09 2009
next sibling parent Walter Bright <newshound1 digitalmars.com> writes:
You can use the -v switch to dmd which will show the linker command line 
it tries.
Mar 09 2009
prev sibling next sibling parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Jacob Carlborg wrote:

 The problem is if compile like this for example: "dmd -L-framework 
 Carbon main.d" dmd complains that it can't find Carbon.d. It seems that 
 it takes everything as a D source file if it doesn't recognize it as a 
 compiler switch.

Seems it needs the -L flag on each: dmd -L-framework -LCarbon main.d Because -Xlinker is being used, "-Wl,-framework,Carbon" doesn't work. --anders
Mar 09 2009
parent reply Jacob Carlborg <doob me.com> writes:
Anders F Björklund wrote:
 Jacob Carlborg wrote:
 
 The problem is if compile like this for example: "dmd -L-framework 
 Carbon main.d" dmd complains that it can't find Carbon.d. It seems 
 that it takes everything as a D source file if it doesn't recognize it 
 as a compiler switch.

Seems it needs the -L flag on each: dmd -L-framework -LCarbon main.d Because -Xlinker is being used, "-Wl,-framework,Carbon" doesn't work. --anders

It worked. Thanks. It's a little annoying that all three compilers have to use different commands for this.
Mar 12 2009
parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Jacob Carlborg wrote:

 Seems it needs the -L flag on each: dmd -L-framework -LCarbon main.d

 Because -Xlinker is being used, "-Wl,-framework,Carbon" doesn't work.

to use different commands for this.

Yeah, it's somewhat annoying. Versions have the same problem, too: dmd -version=foo gdc -fversion=foo ldc -d-version=foo Of course one can use a build tool or development environment to add those, or use the gdmd and ldmd wrappers which might not work for libs. (it would however be nice if DMD for Mac OS X could be taught to accept the most straightforward syntax for it, i.e. "dmd -framework Carbon") The most intriguing part was trying to link frameworks with "pragma", where the build tool will automatically add a friendly "-l" for you... The workaround is to include a library that is always available/used, and then append the real framework linker flags after that library: version (build) { pragma(link, "System -framework Carbon"); } --anders
Mar 13 2009
parent reply Jacob Carlborg <doob me.com> writes:
Anders F Björklund wrote:
 Jacob Carlborg wrote:
 
 Seems it needs the -L flag on each: dmd -L-framework -LCarbon main.d

 Because -Xlinker is being used, "-Wl,-framework,Carbon" doesn't work.

have to use different commands for this.

Yeah, it's somewhat annoying. Versions have the same problem, too: dmd -version=foo gdc -fversion=foo ldc -d-version=foo Of course one can use a build tool or development environment to add those, or use the gdmd and ldmd wrappers which might not work for libs. (it would however be nice if DMD for Mac OS X could be taught to accept the most straightforward syntax for it, i.e. "dmd -framework Carbon")

I asked that ldc should add this but they said something about a linker flag shouldn't be available as a compiler flag.
 The most intriguing part was trying to link frameworks with "pragma",
 where the build tool will automatically add a friendly "-l" for you...
 The workaround is to include a library that is always available/used,
 and then append the real framework linker flags after that library:
 
 version (build) { pragma(link, "System -framework Carbon"); }
 
 --anders

I didn't know you could do that. It would be nice if the built in pragma(lib, ""); would work like pragma(link, "");
Mar 14 2009
parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Jacob Carlborg wrote:

 (it would however be nice if DMD for Mac OS X could be taught to accept
 the most straightforward syntax for it, i.e. "dmd -framework Carbon")

I asked that ldc should add this but they said something about a linker flag shouldn't be available as a compiler flag.

I guess that prefixing -L to the linker flags is the way to go then.
 The most intriguing part was trying to link frameworks with "pragma",
 where the build tool will automatically add a friendly "-l" for you...
 The workaround is to include a library that is always available/used,
 and then append the real framework linker flags after that library:

 version (build) { pragma(link, "System -framework Carbon"); }

I didn't know you could do that. It would be nice if the built in pragma(lib, ""); would work like pragma(link, "");

Me neither, it was more of a desperate attempt to try to convert the wx-config --libs into something that bud/build could make use of... Naturally it failed anyway, due to some weird linking order issues, but at least it tried - and wx.libs looks reasonable enough to me. Don't think pragma(lib) ever worked here, but saw it in D 1.037 Think it was http://d.puremagic.com/issues/show_bug.cgi?id=1690 --anders
Mar 15 2009
prev sibling parent Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
On Mon, Mar 9, 2009 at 4:36 PM, Jacob Carlborg <doob me.com> wrote:
 If I understand things correct dmd uses gcc to do the linking on linux and
 osx, therefore I should be able to link against frameworks on osx.

 GDC/GCC uses the compiler flag "-framework Carbon" and the passes the same
 flag to the linker. LDC/LLVM uses the linker flag "-framework=Carbon" which
 I can pass to the linker using "-L". But I can't figure out how to do that
 with DMD.

 The problem is if compile like this for example: "dmd -L-framework Carbon
 main.d" dmd complains that it can't find Carbon.d. It seems that it takes
 everything as a D source file if it doesn't recognize it as a compiler
 switch.

Just a shot, but -L"-framework Carbon" ?
Mar 09 2009