.obj to .exe using CodeBlocks

I am trying to rework some older code for Windows Vista and 7 (and other platforms as possible). I have almost all the source code (C and C++) but my developer did not make it clear which code was used to compile and link to make the 32 bit executable which I have.

I have been able to use Resource Hacker on my existing 32 bit executable to introduce a new company logo and release date and will make this into a self extracting executable using iexpress, nsis or Self extracting Archive utility 16.0 So far so good.

However, I would like to get a fuller understanding of my programme and ideally take it to other platforms including symbian and wonderware.

By using IDA pro on the .obj files that I have, I have been able to obtain a list of all the elements of source, INC and RC files used in the original compilation. However I am missing four out of thirty six referenced files. This means I may not be able to recompile and link - I have not tried to as yet.

I thought that another way of making progress would be with the 32 bit .obj and .res files which I have. (I also have a .ide file).Is there a way of using CodeBlocks to purely link the existing .obj and .res files.

I created a project and added the existing files. The .res file came up under Resources and I noticed that it was greyed out. The nine .obj files (and one .tr2 and one .td2 file) appeared under Others, again greyed out. CodeBlocks appears to need priming in the linker settings and search directories. I have used linker settings of:

I have been unsuccessful in using GoLink.exe to link my .obj files, as it does not support the OMF format that my .obj files are in.

This means that I will try to do as you say.

Are the linker and directory settings that I gave in my first posting OK in your opinion?

I will enter the eleven .c and one .cpp files as project files; the eight .h, one.rh and one .hex files will be in my INC folder and the one .rc and four .rh and two .dlg will be in my RC folder. I also have a .ide file which I think is redundant to the process but that I will put in as a project file.

2 "Path to Libraries go under go under "Project" -> "Build Options" [Correct Target] Tab "Search Directories" Sub-Tab "Linker". Here, for both Debug and Release, I have put C:\sip2011\USR\BC\INC and C:\sip2011\USR\BC\RC which is where both INC and RC reside

I have put all the files that I found by using IDA Pro on sip32.obj (from which my working sip32.exe came) into the Project using Project->Add files. I find that some of these are greyed out. What is the significance of this?

I am trying to recompile with Code::Blocks using the source code and .obj data that I have inherited without specifically being told which files were involved, so it is an uphill battle O.K.

I have a confusion, please can you help: should my .rh files go with the .h files or with the .rc files? In several areas, my code calls for #include “ sipadv.rh” so I have put a copy of it in my INC folder - it was originally in my RC folder.

With these these improvements, when I ran the build, I got a build log of process terminated with 5 errors and 5 warnings.

The errors you have posted are due to old (very old.. from the days when 16bit computers where common-place) C code that uses these "far" and "huge" keywords for the pointer type "DIBPTR". These keywords are completely obsolete nowadays. I guess they are not supported by C++ compilers (one of the few special features of C that has not been kept backward-compatible in C++). So make sure that all the code that uses this sip.h gets compiled by a C compiler (gcc) and usually all files ending with .c should also be compiled by a C compiler (although the guy who wrote the code may have been sloppy with this as people sometimes write C++ code in .c files because they are stupid). I'm not in any way familiar with CodeBlocks build system so I cannot tell you how to make this work (if you are really hoping to compile this cross-platform, I might suggest you use cmake for the build system).

For a quick-fix of your error above, you could just remove the far and huge keywords and it should work. However, this error might just be the tip of the iceberg. Compiling very old C code in a C++ compiler or interfacing it to C++ code is usually difficult and sometimes it might be easier to just re-implement it in C++ (or at least C-style code that is usable with a C++ project).

Surprisingly enough, I have got all but one of my original .c files to compile to .o compiled files using .gcc in Code::Blocks. My problem now is linking.

I have tried analysing the original.exe using IDA pro demo, but I could nor get a clear picture from this of the object files used.

As I don't know exactly which of my .o files need to be linked to create my new .exe. I thought that I would try linking the .o files that I have and see what transpired.

I have also analysed the original sip32.exe using depends.exe and obtained a listing of the .DLLs called at runtime.

I thought that if entered all these libraries at Project > Project build options > linker settings > Link Libraries using the stripped library name (deleting lib prefix and leaving off the .a), I should by default be using all the linking libraries that I need.

When I ran Build > Build and Run half the libraries came up as not existing (not in my C:\MinGW\lib or C:\MinGW\lib\gcc\Mingw32\4.5.0 - as I confirmed).

I deleted reference to these libraries and again ran Build > Build and Run.

I am a little surprised by this as my code has been well written - as far as I can tell - and has compiled, linked and successfully run before. I would have thought that all the references were there already.

You are definitely just missing a library of some kind. After searching on google for some of these functions, it would seem that these are not part of some off-the-shelf library (win32 or something). I would guess that these are part of the SIP (?) code that you have. Try making a in-file search for some of these function names in all your source files. You should be able to figure out in which source files these functions are defined and make sure you have linked those compiled units too (remember that the ordering of linked objects does matter!).

If you don't find the functions is the sources you have, try looking at the includes of the files that use those functions and find the header files in which they are declared (you have those headers for sure since you were able to compile them). Then, you will just need to figure out which libraries these header files are supposed to link to.

Thanks for your reply which is encouraging and gives me something to work on. I will let you know what I find.

In the meantime, the ordering of linked objects troubles me:

1. How do I determine the sequence that they should be linked?

2. How do I make gcc ld follow that sequence in Code::Blocks?

At the moment, it seems to me that if you force the compile order by using file>Properties>build>priority weight 0-100 (0 = highest priority = first), the linking follows suit. And I can see that you can specify compile and/or linking order - so I guess I have answered question 2.

To give more information, which might help in the resoluti9on of the linking issue, I amm attaching the build log of my compile and link so far

Thanks for your reply which is encouraging and gives me something to work on. I will let you know what I find.

In the meantime, the ordering of linked objects troubles me:

1. How do I determine the sequence that they should be linked?

2. How do I make gcc ld follow that sequence in Code::Blocks?

At the moment, it seems to me that if you force the compile order by using file>Properties>build>priority weight 0-100 (0 = highest priority = first), the linking follows suit. And I can see that you can specify compile and/or linking order - so I guess I have answered question 2.

To give more information, which might help in the resoluti9on of the linking issue, I amm attaching the build log of my compile and link so far

You are definitely just missing a library of some kind. After searching on google for some of these functions, it would seem that these are not part of some off-the-shelf library (win32 or something). I would guess that these are part of the SIP (?) code that you have. Try making a in-file search for some of these function names in all your source files. You should be able to figure out in which source files these functions are defined and make sure you have linked those compiled units too (remember that the ordering of linked objects does matter!).

If you don't find the functions is the sources you have, try looking at the includes of the files that use those functions and find the header files in which they are declared (you have those headers for sure since you were able to compile them). Then, you will just need to figure out which libraries these header files are supposed to link to.

“You are definitely just missing a library of some kind. After searching on google for some of these functions, it would seem that these are not part of some off-the-shelf library (win32 or something). I would guess that these are part of the SIP (?) code that you have. Try making a in-file search for some of these function names in all your source files. You should be able to figure out in which source files these functions are defined and make sure you have linked those compiled units too (remember that the ordering of linked objects does matter!).

If you don't find the functions is the sources you have, try looking at the includes of the files that use those functions and find the header files in which they are declared (you have those headers for sure since you were able to compile them). Then, you will just need to figure out which libraries these header files are supposed to link to.”

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...