On 6 August 2018 at 13:22, Ben Coman <btc@openinworld.com> wrote:
> and ends up with 4 link errors (and 6600 warnings)
> Pharo.exe LNK1120 - 1 unresolved external
> Pharow.exe LNK1120 - 1unresolved external
> sqMain.c.obj LNK2019 - unresolved external symbol _imp_osvm_main��referenced in function main
> sqWin32Main.c.obj LNK2019 - unresolved external symbol _imp_osvm_main referenced in function WinMain
>
> I do see osvm_main is defined here...
> https://github.com/ronsaldo/opensmalltalk-vm/blob/be7b1c03/platforms/minheadless/common/sqVirtualMachineInterface.c#L618
>
> but I'm stuck, I don't understand why its looking for "_imp_osvm_main"

I see that sqMain.c (https://github.com/ronsaldo/opensmalltalk-vm/blob/be7b1c03/platforms/minheadless/common/sqMain.c)
only defines a single function...��
�� �� #include "OpenSmalltalkVM.h"
�� �� int
�� �� main(int argc, const char **argv)
�� �� {
�� �� �� �� return osvm_main(argc, argv);
�� �� }

To check that the osvm_main function is available to be linked, at the end of CmakeLists.txt I see...
�� # Build the VM executable(s)
�� add_executable(${VM_EXECUTABLE_NAME} platforms/minheadless/common/sqMain.c)
�� target_link_libraries(${VM_EXECUTABLE_NAME} ${VM_LIBRARY_NAME} ${VM_DEPENDENCIES_LIBRARIES})

Using https://stackoverflow.com/questions/9298278/cmake-print-out-all-accessible-variables-in-a-script
I found...
�� VM_LIBRARY_NAME=PharoVMCore��
where that library is defined
�� VM_CORE_LIBRARY_TYPE=STATIC��
�� add_library(${VM_LIBRARY_NAME} ${VM_CORE_LIBRARY_TYPE} ${VM_SOURCES} ${VM_INTERNAL_PLUGIN_SOURCES})

and an inspection of PharoVMCore.lib (using 7zip to expand it)��
shows it contains function osvm_main symbol, but not the "_imp_" prefixed symbol.

Regarding the "_imp_" prefix, the next to last comment in this thread
�� * https://software.intel.com/en-us/forums/intel-c-compiler/topic/673427,
gave a hint about the __declspec() needing to be dllexport instead of dllimport.

The declaration for osvm_main() in OpenSmalltalkVM.h is effectively...
https://github.com/ronsaldo/opensmalltalk-vm/blob/be7b1c03/include/OpenSmalltalkVM.h#L43-L55
�� ��#�� �� �� ��define OSVM_VM_EXPORT __declspec(dllexport)
�� ��#�� �� �� ��define OSVM_VM_IMPORT __declspec(dllimport)
�� ��#ifdef BUILD_VM_CORE
�� ��#�� ��define OSVM_VM_CORE_PUBLIC OSVM_VM_EXPORT
�� ��#else
�� ��#�� ��define OSVM_VM_CORE_PUBLIC OSVM_VM_IMPORT
�� ��#endif
�� �� OSVM_VM_CORE_PUBLIC OSVMError osvm_main(int argc, const char **argv);


So the following change to sqMain.c fixes the link error...
�� ����#define BUILD_VM_CORE
�� �� #include "OpenSmalltalkVM.h"
�� �� int
�� �� main(int argc, const char **argv)
�� �� {
�� �� �� �� return osvm_main(argc, argv);
�� �� }

and similar for sqWin32Main.c.

��