PDA

View Full Version : LW92 compiling problems (C++ vs C)



ronaldknol
06-06-2007, 01:12 PM
Hello all,

My plugin broke after the LW7 to LW8 upgrade. We're currently using LW9.2 and so I want to recompile.

I have the LW9.2 SDK. I am using MS Visual Studio 2005 (v8).

The "server.lib" was successfully created, no problems there.

My plugin is in C++ (.cpp files) - and it compiles just fine.

However, it will not link. I am getting linker error "LNK2001: unresolved external symbol" for "_ServerName", "_Activate" and "_ServerClass".

The linker does link with server.lib (as well as some other libraries).

I assume that _ServerName, _Activate and _ServerClass come from the running Lightwave.exe so they are nowhere to be found...???

How do I tell my plugin.cpp file that those symbols are external?

Any help would be appreciated.

Sensei
06-07-2007, 11:23 PM
That's probably job for extern "C"..

I have just renamed servdesc.c and others to servdesc.cpp etc. and then adding to each project without static linking..

jay3d
06-08-2007, 10:16 AM
Hi

I made a LW plugins makefile to use with VC++ Express 2005 with C++ compiling enabled for all files:



PROJ_NAM = <your main project file here without .c extension>

PROJ_OBJ = $(PROJ_NAM).obj servmain.obj <...other sources...>

LIB_OBJ = servdesc.obj \
shutdown.obj \
startup.obj \
username.obj \

SYS_LIB = kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib \
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib

LSDK_INC = C:\lwsdk\include

CC = icl <i'm using Intel C++ compiler, so you can change this value to cl for Microsoft's>

CL_FLAGS = /Ox /I "$(LSDK_INC)" /D "WIN32" /D "_MSWIN" \
/D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "_WINDLL" \
/D "_CRT_SECURE_NO_WARNINGS" /FD /EHsc /MT /W3 /c /Wp64 /TP

LK_FLAGS = $(PROJ_OBJ) server.lib /link /OUT:"$(PROJ_NAM).p" /INCREMENTAL /DLL /DEF:"serv.def" \
/SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /IMPLIB:"$(PROJ_NAM).lib" /MACHINE:X86 \
$(SYS_LIB)

.c.obj::
$(CC) $(CL_FLAGS) $<

$(PROJ_NAM).p: $(PROJ_OBJ) server.lib serv.def
$(CC) $(LK_FLAGS)

server.lib: $(LIB_OBJ)
lib $(LIB_OBJ) /OUT:"server.lib" /SUBSYSTEM:WINDOWS /MACHINE:X86

clean:
del *.p *.lib *.obj *.exp


the server source files must be copied to the project directory or you can use server.lib after compiling for the first time in other projects

and i attached the sample source "MandFilter" from the SDK with modifications necessary for safe C++ compiling ... :)

I think you can use C++ style classes mixed with this code also safely

any suggestions on improving the way are more than welcome!

best regards

TheGarf
06-08-2007, 03:06 PM
any suggestions on improving the way are more than welcome!



Well, integrated 64bit compilation would be nice... :hey:

alexionne
06-08-2007, 11:09 PM
Hi!

I've named my main plugin file DEdgeSlide.cpp (so it uses C++), and I use all those .c files form LW SDK. At the end of DEdgeSlide.cpp, I put

#ifdef __cplusplus
extern "C" {
#endif

char ServerClass[] = LWMESHEDITTOOL_CLASS;
char ServerName[] = "DEdgeSlide";

XCALL_(int) Activate(long version, GlobalFunc *global, LWMeshEditTool *local, void *serverData)
{
return Main(version, global, local, serverData);
}

#ifdef __cplusplus
}
#endif

and it perfectly works :)