Project Home
Project Home
Source Code
Source Code
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - -lang-c++ Linker option: (9 Items)
   
-lang-c++ Linker option  
Dear QNX team, 

qcc supports -lang-c++ and -lang-c option. 
QNX Spec. specified that QCC use  -lang-c++ option as a default but it won't work. 

When I try to build my project which is C code but it include C++ library, if I use QCC without using "-lang-c++" option
, it won't work. 

In case of GCC, it doen't seems like have "-lang-c++" option but I can simplely use "g++ " instead of "gcc" to link C++ 
library to C program. 

Isn't it a bug ? (I'm using qcc V3.3.5)

Thanks,
Dooeui
Re: -lang-c++ Linker option  
Dooeui Hong wrote:
> Dear QNX team, 
> 
> qcc supports -lang-c++ and -lang-c option. 
> QNX Spec. specified that QCC use  -lang-c++ option as a default but it won't work. 
> 
> When I try to build my project which is C code but it include C++ library, if I use QCC without using "-lang-c++" 
option, it won't work. 
> 
> In case of GCC, it doen't seems like have "-lang-c++" option but I can simplely use "g++ " instead of "gcc" to link C+
+ library to C program. 
> 
> Isn't it a bug ? (I'm using qcc V3.3.5)

Are you calling QCC at the link stage and specifying the same compiler 
version used to compile the C++ library?

Regards,

Ryan Mansfield
Re: -lang-c++ Linker option  
Thanks for your replay.

Following is my makefile when I fail to build.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CC = qcc
LD = QCC

CFLAGS += $(DEBUG) -c $(INCLUDES) -V3.3.5,gcc_ntoppcbe -O2
LDFLAGS+= $(DEBUG) -V3.3.5,gcc_ntoppcbe -M 
...

./$(OBJ_DIR)/NADBurnTesterApp : $(OBJECTS)
   $(LD) $(LDFLAGS) -o $@ $(OBJECTS) -L $(LIB_DIR2) -llib_name

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Following is my makefile when it success to build
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CC = qcc
LD = qcc

CFLAGS += $(DEBUG) -c $(INCLUDES) -V3.3.5,gcc_ntoppcbe -O2
LDFLAGS+= $(DEBUG) -V3.3.5,gcc_ntoppcbe -M  -lang-c++  

...

./$(OBJ_DIR)/NADBurnTesterApp : $(OBJECTS)
    $(LD) $(LDFLAGS) -o $@ $(OBJECTS) -L $(LIB_DIR2) -llib_name
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Thanks,
Dooeui
Re: -lang-c++ Linker option  
Dooeui Hong wrote:
> Thanks for your replay.
> 
> Following is my makefile when I fail to build.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> CC = qcc
> LD = QCC
> 
> CFLAGS += $(DEBUG) -c $(INCLUDES) -V3.3.5,gcc_ntoppcbe -O2
> LDFLAGS+= $(DEBUG) -V3.3.5,gcc_ntoppcbe -M 
> ...
> 
> ./$(OBJ_DIR)/NADBurnTesterApp : $(OBJECTS)
>    $(LD) $(LDFLAGS) -o $@ $(OBJECTS) -L $(LIB_DIR2) -llib_name

That looks like it should work. Which host are you using? Windows?

Can you add -v to the link for the failing case and provide the output?

I wrote a very simple test case and was unable to reproduce it. The 
following works:

# cat main.c
int main() { }
# cat hw.cc
#include <iostream>

int foo() {
std::cout << "Hello world" << std::endl;
}
# qcc -V3.3.5,gcc_ntoppcbe main.c -c
# qcc -V3.3.5,gcc_ntoppcbe hw.cc -c
# QCC -V3.3.5,gcc_ntoppcbe main.o hw.o

If I link with qcc instead of QCC, the driver doesn't know it is linking 
in C++ and doesn't link in libsupc++.

Regards,

Ryan Mansfield
Re: -lang-c++ Linker option  
> Dooeui Hong wrote:
> > Thanks for your replay.
> > 
> > Following is my makefile when I fail to build.
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > CC = qcc
> > LD = QCC
> > 
> > CFLAGS += $(DEBUG) -c $(INCLUDES) -V3.3.5,gcc_ntoppcbe -O2
> > LDFLAGS+= $(DEBUG) -V3.3.5,gcc_ntoppcbe -M 
> > ...
> > 
> > ./$(OBJ_DIR)/NADBurnTesterApp : $(OBJECTS)
> >    $(LD) $(LDFLAGS) -o $@ $(OBJECTS) -L $(LIB_DIR2) -llib_name
> 
> That looks like it should work. Which host are you using? Windows?
> 
> Can you add -v to the link for the failing case and provide the output?
> 
> I wrote a very simple test case and was unable to reproduce it. The 
> following works:
> 
> # cat main.c
> int main() { }
> # cat hw.cc
> #include <iostream>
> 
> int foo() {
> std::cout << "Hello world" << std::endl;
> }
> # qcc -V3.3.5,gcc_ntoppcbe main.c -c
> # qcc -V3.3.5,gcc_ntoppcbe hw.cc -c
> # QCC -V3.3.5,gcc_ntoppcbe main.o hw.o
> 
> If I link with qcc instead of QCC, the driver doesn't know it is linking 
> in C++ and doesn't link in libsupc++.
> 

I belive you should call foo in main func. to reproduce it.

//main.c
 int main() 
{ 
 foo();
}





Re: -lang-c++ Linker option  
Dooeui Hong wrote:
> I belive you should call foo in main func. to reproduce it.
> 
> //main.c
>  int main() 
> { 
>  foo();
> }

In my example, foo has C++ linkage so this doesn't work because the 
reference to foo has C linkage. You'd need to either change the linkage 
of foo to have C linkage (using extern "C") or call the function with 
the mangled name.

Regards,

Ryan Mansfield
Re: -lang-c++ Linker option  
Thanks for your help.  

In my program, I programmed it like this,
extern "C"
{
    void foo(void)
   {
      .....
   }
}

I think, Colion is answer is correct for my case

I appreciate your help.
Thanks again. 
Re: -lang-c++ Linker option  
What is your host platform.  If it's windows then the whacky case insensitive nature of the cmd.exe can confuse qcc

Dooeui Hong wrote:
> Dear QNX team, 
> 
> qcc supports -lang-c++ and -lang-c option. 
> QNX Spec. specified that QCC use  -lang-c++ option as a default but it won't work. 
> 
> When I try to build my project which is C code but it include C++ library, if I use QCC without using "-lang-c++" 
option, it won't work. 
> 
> In case of GCC, it doen't seems like have "-lang-c++" option but I can simplely use "g++ " instead of "gcc" to link C+
+ library to C program. 
> 
> Isn't it a bug ? (I'm using qcc V3.3.5)
> 
> Thanks,
> Dooeui
> 
> _______________________________________________
> General
> http://community.qnx.com/sf/go/post14503
> 

-- 
cburgess@qnx.com
Re: -lang-c++ Linker option  
I think your answer makes sense. I used windows cmd.exe.
Thanks a lot.