Page 1 of 1

VC++ 2005 Linker instead of PellesC

Posted: Sun Jul 13, 2008 2:08 pm
by Polo
Hi,

I've talked a lot about the troubles I had using .lib files compiled with VC++ 2005 (or higher) in Purebasic, especially when there's C++ code involved.

It'd be handy if you switched the Purebasic linker to the VC's one, it would require us all to install VC2005 (as you probably cannot distribute it directly in Purebasic), but the result would be much better !

cheers

Posted: Sun Jul 13, 2008 8:45 pm
by Fred
So you probably understand why we don't want to have a 500 MB dependency just to compile an "hello world" in purebasic. We have no problem with pelles C one here, as long you compile the code correctly (as we talked in your thread). BTW, from what i understand, the polink.exe commanline options maps the VC one, did you tried to replace it ?

Posted: Sun Jul 13, 2008 8:55 pm
by Polo
Fred wrote:So you probably understand why we don't want to have a 500 MB dependency just to compile an "hello world" in purebasic. We have no problem with pelles C one here, as long you compile the code correctly (as we talked in your thread). BTW, from what i understand, the polink.exe commanline options maps the VC one, did you tried to replace it ?
No, but I'm going to try :) !
Thanks for the answer, I'll tell you what the results are!

Posted: Sun Jul 13, 2008 9:09 pm
by Polo
Ok, tried, and I got unresolved externals all the way (I copied link.exe and renamed it to polink.exe, plus I copied mspdb80/dll and cvtres.exe)

For a blank source with only "MessageRequester("","")" in it, I get 9 unresolved, which probably means it doesn't link the system lib files ?

(one is __imp__MessageBoxA)

Posted: Mon Jul 14, 2008 1:45 pm
by tinman
Polo wrote:Ok, tried, and I got unresolved externals all the way (I copied link.exe and renamed it to polink.exe, plus I copied mspdb80/dll and cvtres.exe)

For a blank source with only "MessageRequester("","")" in it, I get 9 unresolved, which probably means it doesn't link the system lib files ?

(one is __imp__MessageBoxA)
I've tried this before and got it work with PB4.10 but never bothered doing anything else with it. IIRC the library paths point to the PureLibraries\Windows path, which MSVC doesn't really like. So I was going to write a small stub program which replaced polink.exe, removed all the PellesC stuff and then called the link.exe.

You should also look at the "MSVC2005 command prompt" shortcut for the initialisation required to set the paths for the MSVC tools rather than simply copying the files.

I only got as far as getting the compiled source files from PureBasic and the libraries, but then had to call link manually.

Below is some source which might help you see what's going on when polink is called by PureBasic.

Code: Select all

#include "stdafx.h"
#include <cstdio>
#include <cstdlib>

#include <string>
#include <sstream>
#include <fstream>
#include <vector>

#include <windows.h>

#include "Path.h"

using namespace std;
using namespace nsPath;

void CopyCompilerFiles(void)
{
    CPath   path(nsPath::GetCurrentDirectory());
    
}

int main(int argc, char*argv[])
{
    stringstream    str;
    
    CopyCompilerFiles();
    
    str << "polink_orig.exe ";
    for(int i = 1; i < argc; ++i)
    {
        str << """ << argv[i] << "" ";
    }

    ofstream log("c:\\polink.log");
    log << str.str().c_str();
    log.close();

    Sleep(10000);
    
    return(system(str.str().c_str()));
}

Posted: Mon Jul 14, 2008 2:50 pm
by Polo
Fred wrote:We have no problem with pelles C one here, as long you compile the code correctly
The trouble is, when I follow your instruction, I still get some errors, here they are:
3 unresolved external symbols:

'__security_cookie'
'@__security_check_cookie'
'_imp___iob_func
I don't mind using the PellesC linker but I'd like to have that C++ library running with Purebasic ;)

Posted: Mon Jul 14, 2008 3:03 pm
by Fred
__security_cookie and such can be solved by desactivate the appropriate VC code flag (see C++ -> Code Generation -> Buffer Security Check -> No) or link with bufferoverflowu.lib. For the io problem, that's because we don't use the VC8 runtime, but the standard MSVCRT to be compatiable with older OS without any dependencies. To solve it, you can define this alias as main define: /D__iob_func=__p__iob

Posted: Mon Jul 14, 2008 3:39 pm
by Polo
Fred wrote:__security_cookie and such can be solved by desactivate the appropriate VC code flag (see C++ -> Code Generation -> Buffer Security Check -> No) or link with bufferoverflowu.lib. For the io problem, that's because we don't use the VC8 runtime, but the standard MSVCRT to be compatiable with older OS without any dependencies. To solve it, you can define this alias as main define: /D__iob_func=__p__iob
:shock:

You solved all my problems with 3 lines :!:
Thanks a lot Fred, I don't need to use VC linker now !

Posted: Mon Jul 14, 2008 3:45 pm
by Fred
Good. BTW, using the VC linker wouldn't have solved these problems, as they were not linker related.