Author Topic: .obj to .exe using CodeBlocks  (Read 11180 times)

Offline finston

  • Single posting newcomer
  • *
  • Posts: 6
.obj to .exe using CodeBlocks
« on: December 31, 2010, 05:32:11 pm »
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:

C:\Programme Files\CodeBlocks\minGW\lib\libopengl32.a
libkernel32.a
libgdi32.a
libuser32.a


Search Directories of:

Compiler: the setting for my INC folder

Linker: as above i.e.
C:\Programme Files\CodeBlocks\minGW\lib\libopengl32.a
libkernel32.a
libgdi32.a
libuser32.a

Resource Compiler: the setting of my RC folder


On Build I am getting

"mingw32-g++.exe -Wall  -g    -IC:\2011sip\USR\BC\INC -IC:\2011sip\USR\BC\INC  -c "C:\Documents and Settings\Dave\My Documents\2011sip\SIP\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe -L"C:\Programme Files\CodeBlocks\MinGW\lib\libopengl32.a" -Llibkernel32.a -Llibgdi32.a -Llibuser32.a -L"C:\Programme Files\CodeBlocks\MinGW\lib\libopengl32.a" -Llibkernel32.a -Llibgdi32.a -Llibuser32.a  -o bin\Debug\SIP.exe obj\Debug\USR\BC\CWIN\OUT32\sipadv.res obj\Debug\main.o    -lgdi32 -luser32 -lkernel32 -lgdi32 "C:\Programme Files\CodeBlocks\MinGW\lib\libopengl32.a" -lkernel32 -lgdi32 -luser32
mingw32-g++.exe: obj\Debug\USR\BC\CWIN\OUT32\sipadv.res: No such file or directory
mingw32-g++.exe: C:\Programme Files\CodeBlocks\MinGW\lib\libopengl32.a: No such file or directory
Process terminated with status 1 (0 minutes, 1 seconds)
0 errors, 0 warnings
 

Am I using the wrong settings?

Is there a way to only link using CodeBlocks?

If so how?

Should I use a different linker?

If so what?


HELP, PLEASE - it seems so easy in theory


Finston in a pickle
   

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6538
    • My Best Post
Re: .obj to .exe using CodeBlocks
« Reply #1 on: December 31, 2010, 08:05:24 pm »
Please write real questions after reading the FAQs
http://wiki.codeblocks.org/index.php?title=FAQ#Q:_What_Code::Blocks_is_not.3F

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline finston

  • Single posting newcomer
  • *
  • Posts: 6
Re: .obj to .exe using CodeBlocks
« Reply #2 on: January 02, 2011, 03:49:42 pm »
Thanks fir the reply,tim

I am not going to try linking - point taken.

Can you comment on hoW I have set C::B up as per my last posting, please



Finston

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6538
    • My Best Post
Re: .obj to .exe using CodeBlocks
« Reply #3 on: January 02, 2011, 05:02:49 pm »
Learn the difference between a path to the library (search directories) and the library name.

Libraries go under "Project" -> "Build Options" [Correct Target] Tab "Linker Settings" Sub-Tab "Link Libraries"

Path to Libraries go under go under "Project" -> "Build Options" [Correct Target] Tab "Search Directories" Sub-Tab "Linker"

Learn the basics of using a linker.
Go somewhere like cboard that teaches the basics of programming.

Learn to ask questions that have to do with Code::Blocks.

Read the Manuel and the Wiki pages
http://www.codeblocks.org/user-manual
http://wiki.codeblocks.org/index.php?title=FAQ

Tim S.

 
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline finston

  • Single posting newcomer
  • *
  • Posts: 6
Re: .obj to .exe using CodeBlocks
« Reply #4 on: January 06, 2011, 05:51:11 pm »
I have already looked at (and now revisited) both of the referenced links and taken on board what I can.

They do not make it clear that settings need to be input (I might have expected some resonable defaults), or what they should be and all that I have been able to find are odd snippets in forums of the settings of what worked for them.

Hence my reasonable question, in my opinion, as to whether I have entered the correct details (as per my original posting). I would still like an answer to this, but see below.

Having read your comments I have changed my Project settings as follows:

Your comment 1 "Libraries go under "Project" -> "Build Options" [Correct Target] Tab "Linker Settings" Sub-Tab "Link Libraries". Here, for both Debug and Release, I have placed the filename INC (which is where my .h, .rh files reside) and also RC (which is where my .rc .rh .dlg files reside)

Your comment 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

Question: Do I need to put anything in "Project" -> "Build Options" [Correct Target] Tab "Search Directories" Sub-Tab "Compiler" or "resource compiler"


I have also put all the files which I belive consitute my project into the project under I have already looked at both of the referenced links and taken on board what I can.

They do not make it clear that settings need to be input (I might have expected some resonable defaults), or what they should be and all that I have been able to find are odd snippets in forums of the settings of what worked for them.

Hence my reasonable question, in my opinion, as to whether I have entered the correct details (as per my original posting). I would still like an answer to this, but see below.

Having read your comments I have changed my Project settings as follows:

Your comment 1 "Libraries go under "Project" -> "Build Options" [Correct Target] Tab "Linker Settings" Sub-Tab "Link Libraries". Here, for both Debug and Release, I have placed the filename INC (which is where my .h, .rh files reside) and also RC (which is where my .rc .rh .dlg files reside)

Your comment 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

Note: I am uncertain of the above because I do not think my project files include any libraries

Question: Do I need to put anything in "Project" -> "Build Options" [Correct Target] Tab "Search Directories" Sub-Tab "Compiler" or "resource compiler"


I have put all my project files (as determined from my IDA Pro analysis of sip32.obj of my working sip32.exe) into the Project under Project-> Add files. However some of them are greyed out - what is this all about - no mention of it in the manual?



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.


Thanks replying, please keep helping me


Finston


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.


Thanks replying, please keep helping me


Finston

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6538
    • My Best Post
Re: .obj to .exe using CodeBlocks
« Reply #5 on: January 06, 2011, 06:01:31 pm »
Edit: It looks like you have no idea what an header or Library is; please read the Glossary Links I added below:

An Header normally has the extension .h
An Library normally has the extension .a or .lib (sometimes .dll under Windows or .so under Linux)

Learn the difference between Compiler and Linker steps of the Build Process!

Compilers uses the headers; not the Linkers!
Linkers use the Libraries.

Found a Good Glossary of C++
http://www.glenmccl.com/glos.htm

See Linker http://www.glenmccl.com/glos.htm#tag130

See Header http://www.glenmccl.com/glos.htm#tag107

See Library http://www.glenmccl.com/glos.htm#tag127

CB Related Note: CB defaults to adding "lib" and the correct extension to the library name;
  therefore try using the library name without the lib prefix or the file extension.   

Tim S.
« Last Edit: January 06, 2011, 09:40:48 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline finston

  • Single posting newcomer
  • *
  • Posts: 6
Re: .obj to .exe using CodeBlocks
« Reply #6 on: January 14, 2011, 03:22:55 pm »
Tim, I think that I may be beginning to see the light! Thank you.


I have now set:

Linker settings>link library>gdi32

Search Directories>Compiler>C:2011sip\USR\BC\INC (where my .h files are)

Search Directory>Linker>C:\Programme Files\CodeBlocks\MinGW\lib\libopengl32.a
libkernel32.a
libgdi32.a
libuser32.a

Search Directory>Resource compiler>C:\2011sip\USR\BC\RC (where my .rc and .rh files are)




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 buiuld log of process terminated with 5 errors and 5 warnings.

These are the 5 errors that Code::Blocks gave me on build:

C:\2011sip\USR\BC\INC\sip.h|230|error: expected ',' or '...' before '*' token|
C:\2011sip\USR\BC\INC\sip.h|231|error: expected ',' or '...' before '*' token|
C:\2011sip\USR\BC\INC\sip.h|232|error: expected ',' or '...' before '*' token|
C:\2011sip\USR\BC\INC\sip.h|233|error: expected initializer before '*' token|
C:\2011sip\USR\BC\INC\sip.h|234|error: expected initializer before '*' token|


These are the equivalent lines in sip.h:

DWORD GetDibInfoHeaderSize( DIBPTR );
WORD GetDibWidth( DIBPTR );
WORD GetDibHeight( DIBPTR );
DIBPTR GetDibBitsAddr( DIBPTR );
DIBPTR ReadDib( char * );

And here is something relevant to DIBTR from the beginning of sip.h:

// Define DIB pointers.
#ifdef __FLAT__ // 32 Bit flat memory.
#define DIBPTR BYTE FAR *
#else
#define DIBPTR BYTE huge *
#endif


Can you make any suggestions, please


Finston

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6538
    • My Best Post
Re: .obj to .exe using CodeBlocks
« Reply #7 on: January 14, 2011, 03:52:54 pm »
Search Directory>Linker>C:\Programme Files\CodeBlocks\MinGW\lib\libopengl32.a
libkernel32.a
libgdi32.a
libuser32.a

Why are you still doing this? Why do you think this is right.
Hint: libopengl32.a is NOT a folder/Directory.

Please post the Full Compiler Build Log; if you still what help.
http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F

Post the source code with problem; at least post all of the #includes from the source code.

Note: You really need to go to a site that teaches programming like cboard http://cboard.cprogramming.com/

Tim S.
« Last Edit: January 14, 2011, 05:14:16 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline finston

  • Single posting newcomer
  • *
  • Posts: 6
Re: .obj to .exe using CodeBlocks
« Reply #8 on: March 03, 2011, 06:19:31 pm »
TIM S, I have found a lot of your helpful hints as I have researched further, thanks

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 used Project > Project build options > linker settings > other linker options of:

-Wl,--enable-auto-image-base
-Wl,--add-stdcall-alias
-Wl,--enable-auto-import
-Wl,--enable-stdcall-fixup
-Wl,--cref
-Wl,--trace
which I found on the internet

and Project > Project Build options > Compiler settings > Other options of:
-mthreads
-fmessage-length=0
-m32
-mwindows
-v
-fmax-errors=0
again found on the internet

What I found was that the link libraries used are
kernel32
gdi32
user32
mingw32
gcc
ntdll
msvcrt
comdlg32
gcc_s
moldname

The libraries that I entered are not mentioned unless they are not present in C:\MinGW\lib or C:\MinGW\lib\gcc\Mingw32\4.5.0 and it makes no difference if I keep them or deleted all the link Libraries

What I get as Error messages are:

Code: [Select]
C:/2011sip/SIP/Sipprt.c:185: undefined reference to `Plot_Axes'
C:/2011sip/SIP/Sipprt.c:187: undefined reference to `Plot_Data'
obj\Debug\sipwnd.o: In function `WndProc@16':
C:/2011sip/SIP/sipwnd.c:138: undefined reference to `Read_Ini_Int'
C:/2011sip/SIP/sipwnd.c:140: undefined reference to `File_Init'
C:/2011sip/SIP/sipwnd.c:142: undefined reference to `Ex_File_Init'
C:/2011sip/SIP/sipwnd.c:197: undefined reference to `File_Open_Dlg'
C:/2011sip/SIP/sipwnd.c:201: undefined reference to `Sip_File_Read'
C:/2011sip/SIP/sipwnd.c:234: undefined reference to `Ex_File_Save_Dlg'
C:/2011sip/SIP/sipwnd.c:248: undefined reference to `File_Export'
C:/2011sip/SIP/sipwnd.c:262: undefined reference to `File_Export'
C:/2011sip/SIP/sipwnd.c:272: undefined reference to `File_Export'
C:/2011sip/SIP/sipwnd.c:290: undefined reference to `File_Save_Dlg'
C:/2011sip/SIP/sipwnd.c:304: undefined reference to `Sip_File_Write'
C:/2011sip/SIP/sipwnd.c:321: undefined reference to `Sip_File_Write'
C:/2011sip/SIP/sipwnd.c:471: undefined reference to `Analyse_Data'
obj\Debug\sipwnd.o: In function `PlotWndProc@16':
C:/2011sip/SIP/sipwnd.c:1251: undefined reference to `Plot_Axes'
C:/2011sip/SIP/sipwnd.c:1253: undefined reference to `Plot_Data'

if I delete the troublesome sipwnd.c from the compile and link, I get:

Code: [Select]
obj\Debug\Sip32.o: In function `WinMain@16':
C:/2011sip/SIP/Sip32.c:161: undefined reference to `WndProc@16'
C:/2011sip/SIP/Sip32.c:192: undefined reference to `StatBarProc@16'
C:/2011sip/SIP/Sip32.c:199: undefined reference to `PlotWndProc@16'
C:/2011sip/SIP/Sip32.c:207: undefined reference to `PlotTitleWndProc@16'
C:/2011sip/SIP/Sip32.c:215: undefined reference to `PlotStatWndProc@16'
obj\Debug\Sipdlg.o: In function `DialWndProc@16':
C:/2011sip/SIP/Sipdlg.c:273: undefined reference to `bRtData'
C:/2011sip/SIP/Sipdlg.c:275: undefined reference to `bStData'
C:/2011sip/SIP/Sipdlg.c:308: undefined reference to `bRtData'
C:/2011sip/SIP/Sipdlg.c:310: undefined reference to `bStData'
obj\Debug\Sipprt.o: In function `Print_Data':
C:/2011sip/SIP/Sipprt.c:185: undefined reference to `Plot_Axes'
C:/2011sip/SIP/Sipprt.c:187: undefined reference to `Plot_Data'

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.

I am at a loss to know how to proceed - any ideas?


Thanks


Finston

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6538
    • My Best Post
Re: .obj to .exe using CodeBlocks
« Reply #9 on: March 03, 2011, 07:05:56 pm »

Note: You really need to go to a site that teaches programming like cboard http://cboard.cprogramming.com/

Tim S.


If you know where File_Export is defined; I might be able to help; if you do not you need someone to help you how knows how to program and can see all of your sourcecode!!
C:/2011sip/SIP/sipwnd.c:262: undefined reference to `File_Export'
« Last Edit: March 03, 2011, 07:12:46 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline finston

  • Single posting newcomer
  • *
  • Posts: 6
Re: .obj to .exe using CodeBlocks
« Reply #10 on: March 08, 2011, 12:58:13 pm »
Tim, thank you for your reply

File_Export is first in my Sip.h file, six or so lines from the end, as:

BOOL File_Export( short FAR *, unsigned short, unsigned short,
                  unsigned short, LPSTR   );

 and then, as I understand it defined in my SIPFILE.c as:


BOOL File_Export( short FAR *Data,         // Pointer to data.
                  unsigned short nXinc,    // X axis increment.
                  unsigned short nyPoints, // Number of y points.
                  unsigned short nyVals,   // Number of y values per point.
                  LPSTR lpstrFileName   )  // Pointer to file name.


It is then used in my sipwnd.c file at lines :


line 248, 262 and 272 (the three lines giving the errors, typically  C:\2011sip\SIP\sipwnd.c|248|undefined reference to `File_Export'|

              case 2: // If file data present...

                if( File_Export(( short FAR * )( lpstrFileData +
                                                    sizeof( t_fhead )),
                                ( unsigned short )
                                (( t_fhead FAR * )lpstrFileData )->xinc,
                                ( unsigned short )
                                (( flen - sizeof( t_fhead ))
                                / ( 2 * nDatDiv )),
                                ( unsigned short )nDatDiv,
                                ( LPSTR )szFqFileName ))
                  EnableMenuItem( hMenu, IDM_EXPORT, MF_DISABLED | MF_GRAYED);
                 break;

              case 3: // If real time data present...

                if( File_Export(( short FAR * )RxData,
                                ( unsigned short )rtint_seconds,
                                ( unsigned short )rt_npoints,
                                ( unsigned short )nDatDiv,
                                szFqFileName ))
                  EnableMenuItem( hMenu, IDM_EXPORT, MF_DISABLED | MF_GRAYED);
                 break;

              case 4: // If stored data present...

                if( File_Export(( short FAR * )RxData,
                                ( unsigned short )stint_seconds,
                                ( unsigned short )st_npoints,
                                ( unsigned short )nDatDiv,
                                szFqFileName ))
                  EnableMenuItem( hMenu, IDM_EXPORT, MF_DISABLED | MF_GRAYED );
                break;
            }// Switch;
          }
          return 0;



Thanks

Finston

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: .obj to .exe using CodeBlocks
« Reply #11 on: March 08, 2011, 01:09:12 pm »
We have left the scope of this forum by far.

The questions are no longer related to C::B !
This violates our forum rules !

Topic locked !