gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > (CAPTURED!)Hunting for a sed expression for linking errors..

#120718 - Izhido - Mon Mar 05, 2007 7:53 pm

Hi guys!

I have the following program:

Code:

void Test1();

void Test2(int a);

void Test3(float b, char* c);

int main()
{
   Test1();
   Test2(5);
   Test3(8.3f, "hello!");
}


This program, though compiles, does not "link" (evidently :D ).

When compiled by Visual C++ 2005 Express / Win32 platform, it gives us the following output:

Code:

------ Rebuild All started: Project: LinkingErrorTestWin32, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'LinkingErrorTestWin32', configuration 'Debug|Win32'
Compiling...
main.cpp
Linking...
main.obj : error LNK2019: unresolved external symbol "void __cdecl Test3(float,char *)" (?Test3@@YAXMPAD@Z) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "void __cdecl Test2(int)" (?Test2@@YAXH@Z) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "void __cdecl Test1(void)" (?Test1@@YAXXZ) referenced in function _main
C:\PRJ\LinkingErrorTest\Debug\LinkingErrorTestWin32.exe : fatal error LNK1120: 3 unresolved externals
Build log was saved at "file://c:\PRJ\LinkingErrorTest\LinkingErrorTestWin32\Debug\BuildLog.htm"
LinkingErrorTestWin32 - 4 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========


Additionally, the "Error List" window shows the 3 linking errors.

When compiled with devkitPro (also using Visual C++ 2005 Express), this is the output:

Code:

------ Rebuild All started: Project: LinkingErrorTestNDS, Configuration: Debug Win32 ------
Performing Makefile project actions
clean ...
main.cpp
arm-eabi-g++ -MMD -MP -MF /c/PRJ/LinkingErrorTest/LinkingErrorTestNDS/Debug/main.d -g -Wall -O2 -mcpu=arm9tdmi -mtune=arm9tdmi -fomit-frame-pointer -ffast-math -mthumb -mthumb-interwork -I/C/PRJ/LinkingErrorTest/LinkingErrorTestNDS -I/C/devkitPro/libnds/include -I/c/PRJ/LinkingErrorTest/LinkingErrorTestNDS/Debug -DARM9 -fno-rtti -fno-exceptions -c /C/PRJ/LinkingErrorTest/LinkingErrorTestNDS/main.cpp -o main.o
linking LinkingErrorTestNDS.elf
main.o: In function `main':
c:/PRJ/LinkingErrorTest/LinkingErrorTestNDS/main.cpp(9): undefined reference to `Test1()'
c:/PRJ/LinkingErrorTest/LinkingErrorTestNDS/main.cpp(10): undefined reference to `Test2(int)'
c:/PRJ/LinkingErrorTest/LinkingErrorTestNDS/main.cpp(11): undefined reference to `Test3(float, char*)'
collect2: ld returned 1 exit status
make[1]: *** [/c/PRJ/LinkingErrorTest/LinkingErrorTestNDS/LinkingErrorTestNDS.elf] Error 1
make: *** [Debug] Error 2
Build log was saved at "file://c:\PRJ\LinkingErrorTest\LinkingErrorTestNDS\Debug\BuildLog.htm"
LinkingErrorTestNDS - 0 error(s), 0 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========


However, this time, the Error List window shows no linking errors.

I've been told this is because of the "regular expression" submitted to the "sed" command line tool during compilation. I must confess I haven't the slightest idea of how to build sed regexp strings.

Anyone here with sed expertise can provide us with an regexp that let us see linking errors in the Error List tab of Visual C++ 2005 Express?

The current, recommended regexp for Visual C++ 2005 Express is:

Code:

's/\(.[a-zA-Z]\+\):\([0-9]\+\):/\1(\2):/'


Any help will be greatly appreciated!

- Izhido


Last edited by Izhido on Wed Mar 07, 2007 7:37 pm; edited 1 time in total

#120723 - rodif - Mon Mar 05, 2007 8:17 pm

*must read full comment before posting*

#120745 - gmiller - Mon Mar 05, 2007 10:29 pm

Not sure what rodif is worried about but the regular expression to recognize link error output should be similar to the current one which is targeted at the error messages from the compiler. I do not know if the ones you are seeing are the generic enough to be used for building a regular expression that will catch just link errors so I will need to do a little looking. If I can find a definition of the link error format I will post it and if I can a regular expression to find it. I need the same thing for a project I want to do as well so the effort is helping me as well.

#120750 - keldon - Mon Mar 05, 2007 10:44 pm

Do you have a new line at the end of the file? And do you have the function stubs filled out? Why not first try to compile a file with only main. Then go straight for printing "hello world".

#120780 - wintermute - Tue Mar 06, 2007 1:41 am

Izhido wrote:

Anyone here with sed expertise can provide us with an regexp that let us see linking errors in the Error List tab of Visual C++ 2005 Express?

The current, recommended regexp for Visual C++ 2005 Express is:

Code:

's/\(.[a-zA-Z]\+\):\([0-9]\+\):/\1(\2):/'


Any help will be greatly appreciated!



Took me a bit of fiddling to find what you were actually referring to here but I found it in the end. My msvc++ 2005 Express had the error list switched off and was only showing the output from make.

Anyway, this should do what you want

Code:

make 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):/\1(\2):/' -e 's/\(undefined reference\)/error : \1/'



Keldon: Did you actually read the post, that's a pretty odd reponse.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#120857 - rodif - Tue Mar 06, 2007 8:56 pm

I think keldon did the same thing i did; Read the part about funcitons not linking then respond telling him how to properly link the functions in question. Instead of reading the whole post.

#120859 - keldon - Tue Mar 06, 2007 9:12 pm

rodif wrote:
I think keldon did the same thing i did; Read the part about funcitons not linking then respond telling him how to properly link the functions in question. Instead of reading the whole post.


Yes, I didn't read the post properly at all.

#120863 - rodif - Tue Mar 06, 2007 9:32 pm

http://www.xs4all.nl/~borkhuis/vxworks/vxw_pt1.html#1.13
Quote:
Q: When using Visual Studio as development environment and the GNU compiler to compile Visual Studio does not recognise the output of the compiler.

A: Using the following program to filter the output of the GNU compiler it is possble to compile the code: gnu2msdev.cpp
The rule to compile using this program is (the name of the comiled executable is gnu2msdev.exe:

%.o : %.cpp
-$(CXX) $(C++FLAGS) $(ADD_FLAGS) -c $< -o $(@F) 2> $(TMP)\ccerr.txt
@type $(TMP)\ccerr.txt | gnu2msdev

(From: f.pertin@staubli.com)


I've used this program before. Maybe you can make some changes to it to get what you're looking for?

#120960 - Izhido - Wed Mar 07, 2007 7:32 pm

WinterMute: Absolutely wonderful! Works like a charm!

Thanks!

PS.: This deserves a change on the devkitPro site FAQ for integration with Visual Studio :D .