The answer to your IT questions
 

Advanced search  • Search tips
My QUESTIONS & ANSWERS
 Question:

How to build a dll with makefile? Please give a sample.

User Asked by: stenton
Published on: 10:28/07.05.2008
Status: OPEN
I want to build a DLL from cpp source files. Please give me sample how to build DLL using NMAKE.exe or MAKE.exe and makefile.
 Answers: 1
Sort by: /\ date | rating
Image Answer by: xpert
Posted on: 10:28/07.05.2008
Rating: 1 from possible 5 with 2 votes
Here is sample, but of course you have to remove stuff that you don't need:

"Makefile"


#vars
OUTDIR = dist
TARGETDLL = $(OUTDIR)\mydll.dll
CPP_LOCATION = src\*.cpp
LINK_LIBS = usedlib1.lib usedlib2.lib  usedlib3.lib

VS_INC_VC=/I"$(VS_INSTALL_DIR)\VC\include" /I"$(VS_INSTALL_DIR)\VC\PlatformSDK\include"

VS_LIB_VC=/LIBPATH:"$(VS_INSTALL_DIR)\VC\PlatformSDK\Lib" /LIBPATH:"$(VS_INSTALL_DIR)\VC\lib" /LIBPATH:"my_path_to_resources\resources" 
ADD_COMPILER_OPTS = /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL" /D "_VC80_UPGRADE=0x0700" /D "_WINDLL" /D "_ATL_MIN_CRT" /D "_MBCS" /Gm /EHsc /RTC1 /MTd /GR- /Fo"$(OUTDIR)\\" /Fd"$(OUTDIR)\vc80.pdb" /W3 /nologo /c /Wp64 /ZI /TP /errorReport:prompt  

ADD_LINKER_OPTS=/INCREMENTAL /NOLOGO /DLL  /DEBUG /PDB:"$(OUTDIR)\mydll.pdb" /SUBSYSTEM:WINDOWS /IMPLIB:"$(OUTDIR)\mydll.lib" /MACHINE:X86 /ERRORREPORT:PROMPT

all: prepare makeMyDll clean
prepare:
 del $(OUTDIR) /q /S
 mkdir $(OUTDIR)
objfiles :
 cl   $(ADD_COMPILER_OPTS) $(VS_INC_VC) $(CPP_LOCATION)

makeMyDll : objfiles
 link $(VS_LIB_VC) /OUT:"$(TARGETDLL)" $(ADD_LINKER_OPTS)  $(LINK_LIBS) $(OUTDIR)\*.obj
 copy $(TARGETDLL) ..
 
clean :
 del $(OUTDIR)\*.* /q /S
 rmdir $(OUTDIR) /q


you will also need a sample setenv.bat where you will set environment variables. Here is a sample of variables for Microsoft Visual studio 8:

"SetEnv.bat"


@echo off
if not "%VS_INSTALL_DIR%" == "" goto gotVSInstall
set VS_INSTALL_DIR=C:\Program Files\Microsoft Visual Studio 8
:gotVSInstall
if exist "%VS_INSTALL_DIR%\SDK\v2.0\Bin\nmake.exe" goto okHome
echo The VS_INSTALL_DIR environment variable is not defined correctly
goto end

:okHome

set PATH=%VS_INSTALL_DIR%\bin;%VS_INSTALL_DIR%\PlatformSDK\bin;%VS_INSTALL_DIR%\PlatformSDK\Lib;%VS_INSTALL_DIR%\PlatformSDK\Lib\AMD64;%VS_INSTALL_DIR%\Common7\Tools;%VS_INSTALL_DIR%\Common7\IDE;%VS_INSTALL_DIR%\Common\Tools;%VS_INSTALL_DIR%\Common\IDE;%VS_INSTALL_DIR%;%VS_INSTALL_DIR%\VC\lib;%PATH%

:end


Create two files with above content, enter console with "cmd" command from windows, type "setenv.bat", then type nmake which will take the default name "makefile" without extension.
Vote:

Please vote! Your opinion matters!
If you haven't found what you've looking for, post a question
  
| Home | Hall of fame | Register | Log in | Terms of service | Help | Contacts |