Jump to content

Silly q: object files & hcustom - friends or foes?


Recommended Posts

I should probably know this, but haven't come across it in any of the docs soooo....

I like to use lots of .C/.h pairs. Typically, I create a makefile that makes a lot of object files & then links them all together in the end. can you do something like this with hcustom?

I've always cheated it by #including the .C's in the .h's for hcustom, but that is becoming a bore. :P

Link to comment
Share on other sites

Guest xionmark
I like to use lots of .C/.h pairs.  Typically, I create a makefile that makes a lot of object files & then links them all together in the end.  can you do something like this with hcustom?

I've always cheated it by #including the .C's in the .h's for hcustom, but that is becoming a bore.  :P

15257[/snapback]

I've wondered the very same thing and only found the "-l" & "-L" switches that can be passed to hcustom, but I haven't tried to use them yet.

On a related note, I've been wondering how to pass compiler options to hcustom, I've recently looked at the "-d" switch (on WIN-XP) but it doesn't appear to pick up the CFLAGS environment var.

--Mark

> hcustom
Usage:  hcustom [-g] [-s] [-t] [-L libdir] [-I incdir]
                [-l libname] [-i dir] source_files

This program will make custom plug-ins (DSO's) for Houdini.

Options:
  -d          Display CFLAGS environment variable passed to hcompile
  -g          Create debug version of the DSO
  -i dir      Specify an install directory (default HOME\houdini7.0\dso)
  -s          Create a stand alone application instead of a DSO
  -l libname  Link with the library named libname;  libraries are passed
              to the compiler in the order in which they are given
  -L libdir   Add libdir to the library file search path
  -I incdir   Add incdir to the include file search path
  -t          Turn of creation of tagging information.  At least one
              object file in an archive must have the tagging
              information for Houdini to load the .dll successfully
>

Link to comment
Share on other sites

Guest xionmark
FYI (I don't know if this is what you're refering to, but...): to display the CFLAGS using the -d, you have to actually give it a .C file to compile, i.e.:

hcustom -d someFile.C

if you just "hcustom -d", it will not display anything.

15276[/snapback]

Ah, thanks, just tried it.

--Mark

Link to comment
Share on other sites

  • 3 months later...
Guest xionmark

Hello,

I've been trying to get this to work for a while but haven't had success yet. At this time I have to build these on WIN-XP machines, no Linux libs available yet so I'm stuck in .NET land ... :ph34r:

This is the hcustom command I'm using, I need to link to an external lib, "mxs.lib".

hcustom -i . -L . -l mxs -d IFD_Maxwell.C

It fails complaining in can't link to the mxs lib. Here's the output from hcustom -d:

hcustom -i . -L . -l mxs -d IFD_Maxwell.C
Linking with 'mxs'
Making 'IFD_Maxwell.o' and '.\IFD_Maxwell.dll' from 'IFD_Maxwell.C'

CFLAGS = -TP -DVERSION="" -DOFSTREAM_PERMISSIONS=", 0666" -DI386 -DWIN32 -DSWAP_BITFIELDS -DDLLEXPORT=__declspec(dllexport)  -I . -I "C:/Program Files/Microsoft
 Visual Studio .NET 2003/VC7/include" -I "C:/Program Files/Microsoft Visual Stud
io .NET 2003/VC7/PlatformSDK/include" -I "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.328/custom/include" -I "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.328/toolkit/include" -Ox -MD -GX -GR -DSESI_LITTLE_ENDIAN -DMAKING_DSO -Fo"IFD_Maxwell.o" -LD -link /libpath:"C:/Program Files/Microsoft Visual Studio .NET 2003/VC7/lib" /libpath:"C:/Program Files/Microsoft Visual Studio .NET 2003/VC7/PlatformSDK/lib" "/libpath:"." "mxs" " "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.328/custom/houdini/dsolib/*.a" -out:"./IFD_Maxwell.dll"

The /libpath for the mxs lib looks different than the others, could this be a bug in hcustom?

So, taking Edward's advice to use the hcustom -d output to build the hcompile commands manualy, I did so, but now hcompile is unhappy ...

Here's the Makefile entry:

CFLAGS= -TP -DVERSION="" -DOFSTREAM_PERMISSIONS=", 0666" -DI386 \
	-DWIN32 -DSWAP_BITFIELDS -DDLLEXPORT=__declspec\(dllexport\)  \
	-I . \
	-I C:/PROGRA~1/MICROS~2.NET/VC7/include \
	-I C:/PROGRA~1/MICROS~2.NET/VC7/PlatformSDK/include \
	-I C:/PROGRA~1/SIDEEF~1/HOUDIN~1.328/custom/include \
	-I C:/PROGRA~1/SIDEEF~1/HOUDIN~1.328/toolkit/include \
	-Ox -MD -GX -GR -DSESI_LITTLE_ENDIAN -DMAKING_DSO \
	-Fo"IFD_Maxwell.o" \
	-LD \
	-link /libpath:C:/PROGRA~1/MICROS~2.NET/VC7/lib \
	/libpath:C:/PROGRA~1/MICROS~2.NET/VC7/PLATFO~1/lib \
	"/libpath:"." "mxs" "  "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.328/custom/houdini/dsolib/*.a" \
	-out:"./IFD_Maxwell.dll"

IFD_Maxwell_test:
	hcompile IFD_Maxwell.C

And here's the error output:

[mstory@mercury ~/Maxwell/src]$ make IFD_Maxwell_test
hcompile IFD_Maxwell.C
Usage:  hcompile [-c CC_Program] [-t] file_names ...
    Compile the Houdini Development Kit C++ files using cl -TP.
    The environment variable $CFLAGS can be used to specify any
    options to be passed onto the compiler.  In most cases, this program
    is called from the script 'hcustom' to set the $CFLAGS variable
    properly.
    The -c option allows the compiler string to be passed on the command line
    instead of searching for the HOUDINI_CC environment variable.
    The -t option prevents the creation of the HoudiniGetTagInfo() symbol.
    This can be used when making archives.  At least one object file
    compiled must have the HoudiniGetTagInfo() symbol defined for the DSO
    to load into Houdini.
    Environment Variables:
       HOUDINI_CC - The compiler to run [cl -TP]
       CFLAGS     - The compiler flags
make: *** [IFD_Maxwell_test] Error 1

What am I doing wrong here? It *looks* OK but obviously isn't ...

Help .... please ... :blink:

Thanks!!!

--Mark

Link to comment
Share on other sites

Just because you set up the CFLAGS *makefile* variable, doesn't necessarily means that it sets it into the environment. For more info, please see the documentation of make.

I suggest studying Makefile.win and Makefile.gnu closely if you're using make. For one thing, note that hcompile is no longer necessary.

Link to comment
Share on other sites

Guest xionmark
Just because you set up the CFLAGS *makefile* variable, doesn't necessarily means that it sets it into the environment. For more info, please see the documentation of make.

I suggest studying Makefile.win and Makefile.gnu closely if you're using make. For one thing, note that hcompile is no longer necessary.

17119[/snapback]

Hi Edward,

I forgot to mention that I also did a setenv CFLAGS too, but no luck, so yes I understand the diff between make vars and env vars but I have something screwed up. OK, I just took a look at the Makefiles you mention, thanks, I should be able to figure it out from there.

--Mark

Link to comment
Share on other sites

In windows, don't you have to specify the full file name? i.e. "mxs.lib" as opposed to "mxs"?

I know it sounds silly, but I've always linked my libs that way... at least... I think that's what I did last time I successfully linked a lib. ;)

Link to comment
Share on other sites

Guest xionmark
In windows, don't you have to specify the full file name? i.e. "mxs.lib" as opposed to "mxs"?

I know it sounds silly, but I've always linked my libs that way... at least... I think that's what I did last time I successfully linked a lib. ;)

17129[/snapback]

I tried that too, no luck ... just tried again for a sanity check, no go.

I was hoping it would work with the hcustom command instead of rolling my own Makefile, wish I knew why this won't work.

I checked the lib to make sure the objects were in the lib file too.

--Mark

Link to comment
Share on other sites

Guest xionmark
A bit off-topic, but how do you do that in Windows?

17131[/snapback]

Hi Brian,

Yea, I wanted to make sure the .lib file delivered to me had all the right objects, so I poked around in the $MSVCDir/bin dir and found dumpbin. It has a bunch of switches, but /HEADERS should give you a list of objects, etc. If you've got the MSDN installed there's a little more documentation then what's pooped out from dumpbin itself.

--Mark

Link to comment
Share on other sites

Guest xionmark
It just occurred to me that the way the Makefiles are set up, you should supply the library name in the SYSLIBS variable so that it gets linked in when using LINK, not CC.

17132[/snapback]

Hi Edward,

I made copies of the Makefiles and am editing them for this project and saw the same thing. I'm surprised at some of the changes I have to make, I looked at hcustom.nt too and that helps. Almost there ...

--Mark

Link to comment
Share on other sites

Guest xionmark

OK, I've got the linker to resolve all the symbols and generate a .o file but no .dll file ... I called the linker directly as well from the CC command but no DLL. After comparing the arguments to a successfull DLL build (using hcustom and not calling functions from the 3rd party DLL), I can't see any differences in the arguments to the linker.

Here's an example:

[mstory@mercury ~/Maxwell/src]$ make -f Makefile.gnu
"C:\Program Files\Microsoft Visual Studio .NET 2003\VC7/bin/cl" -TP -MD -GX -GR
-c -DVERSION="7.0.328" -DI386 -DWIN32 -DSWAP_BITFIELDS -DDLLEXPORT="__declspec(d
llexport)" -DSESI_LITTLE_ENDIAN -DOFSTREAM_PERMISSIONS=", 0666"  -I"C:\PROGRA~1\
SIDEEF~1\HOUDIN~1.328/toolkit/include" -I"C:\PROGRA~1\SIDEEF~1\HOUDIN~1.328/cust
om/include" -I"C:\Program Files\Microsoft Visual Studio .NET 2003\VC7/include"
 -DMAKING_DSO -DUT_DSO_TAGINFO='"3262197cbf1f5a742cb414a84a3f83ff3e5cccb0917c87c
e10f990485e46e4887b912bda9f463c71432becfa67c8281c5afaef30f7d8eb5c53634e95049e81b
e4bae508aff924994a3268d0847f848e6ab0386a480f08044feb34f1b0218b826"' IFD_Maxwell.
C -FoIFD_Maxwell.o -LD \
-link -LIBPATH:"C:\Program Files\Microsoft Visual Studio .NET 2003\VC7/lib" " -L
IBPATH:C:\Program Files\Microsoft Visual Studio .NET 2003\VC7/PlatformSDK/lib -L
IBPATH:." "mxs.lib"  -LIBPATH:"C:\PROGRA~1\SIDEEF~1\HOUDIN~1.328/dsolib" "C:\PRO
GRA~1\SIDEEF~1\HOUDIN~1.328/custom/houdini/dsolib/*.a" -out:IFD_Maxwell.dll
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

IFD_Maxwell.C
[mstory@mercury ~/Maxwell/src]$

Any ideas? :unsure:

--Mark

Link to comment
Share on other sites

Guest xionmark

It was the "-c" switch ... now it almost builds the DLL but spews a bunch of other errors ... flippin' Windoze ... marching on ...

It really would be easier if hcustom worked right; can you think of any reason why passing a .lib file using the -l switch doesn't (seem) work?

--Mark

Link to comment
Share on other sites

Guest xionmark

Hi Edward,

Thanks for the help, I think I got all the switches sorted out but as it turns out there was one object missing from the lib file. As soon as that gets resolved, it looks like the build will finish with a complete DLL.

Thanks!

--Mark

Link to comment
Share on other sites

  • 4 months later...

reviving this topic...

So, I hacked together a little script today which allows you to use a regular makefile for creating hdk code when you have multiple .C/.h pairs. Feel free to hack away at it. If you come up with a better solution, post it here. This has only been tested on Linux - I've no idea what will happen using this under Windows with Cygwin or something similar. It's setup just for SOP and VEX code & requires that the filename with the cook method starts with "SOP" or "VEX". I'm sure you can edit that to your liking, but this gets the ball rolling...

The Makefile

note, you *do* have to tell it what your main file is, in this case, it's SOP_RibFile.C

you may also want to specify the path to ml_hcustom

CXX = g++
LIBDIR = -L /usr/X11R6/lib -L /usr/lib/ML
LIBS = -lm -lGLU -lGL -lX11 -lXext -lXi -ldl
INCINC = -I /usr/local/prman/include -I /usr/include/ML -I ~/HDKProjects/MLInclude/

files:= $(wildcard *.C)
objects:= $(files:%.C=%.o)

hcustomfile:= SOP_RibFile.C

%.o : %.C
        ./ml_hcustom $(INCINC) $<
        ar -rv libforme.a $@

$(hcustomfile:.C=.o): $(hcustomfile) $(hcustomfile:.C=.h) $(objects)
        hcustom -L./ -lforme $(LIBDIR) $(LIBS) $(INCINC) $(@:.o=.C)

clean:
        rm -f *~ *.o *.a

cleandso:
        rm -f *~ *.o *.a ~/houdini$(HOUDINI_MAJOR_RELEASE).$(HOUDINI_MINOR_RELEASE)/dso/$(hcustomfile:.C=.so)

ml_hcustom:

#!/bin/tcsh -f

# Script for compiling HDK code with multiple .C/.h pairs.
#
# written 8/23/05 by Brian Knudson at Martian Labs 
#  briank@hero.com
#
# Use, distribute, hack.  Send me a christmas card if you 
# like it.
#

set argv = ( `/usr/bin/getopt l:I:L:h $*` )

set links = ""
set includes = ""
set linkdirs = ""
set hcustomfile = ""
set objects = ""

foreach i ( $* )
    switch ( $i )
        case "-l"
            shift
            echo "linking with $1"
            set links = ("-l$1" $links)
            shift
            breaksw
        case "-I"
            shift
            echo "using include dir $1"
            set includes = ("-I $1" $includes)
            shift
            breaksw
        case "-L"
            shift
            echo "using link dir $1"
            set linkdirs = ("-L$1" $linkdirs)
            shift
            breaksw
        case "-h":
            echo ' '
            echo "Usage:  $0 [options] file list"
            echo 
            echo " This script compiles .C/.h pairs and uses the resuliting"
            echo " objects in hcustom"
            echo
            echo "Options:"
            echo "  -l      use given library"
            echo "  -L      use given directory to find libs"
            echo "  -I      use given directory to find includes"
            echo ' '
            exit
            breaksw
    endsw
end

echo links: $links
echo linkdirs: $linkdirs
echo includes: $includes

shift
foreach f ($argv)
    if ( $f:e =~ C* ) then
        if ( ! ($f =~ SOP* || $f =~ VEX* ) ) then
            sed /\$SHARED/s/\$CC/\#\ \$CC/g `which hcustom` | sed s/hcompile/hcompile\ -t/g > newhcustom && chmod u+x newhcustom
            ./newhcustom $linkdirs $links $includes $f
            rm -f newhcustom
        endif
    endif
end

exit

I suppose you dont' really need all that confirmation being that it's non-interactive, but maybe they'll help you see what I'm trying to do.

real quick summary of how it works: ml_hcustom copies hcustom to the local dir, commenting out the actual "compile into dso" line, and adds a "-t" to the hcompile command. It then uses the local ml_hcustom to make a houdini compliant .o file.

The makefile drops the circular dependency on SOP_RibFile.o, so it only sends the other .C's to the .o rule at the top, where, at the end of compilation, it assembles a library from each of the .o files created above. it then passes that lib into a typical hcustom.

Seems to work.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...