Author Topic: __attribute__ Not Recognized  (Read 8447 times)

Offline spflanze

  • Almost regular
  • **
  • Posts: 134
__attribute__ Not Recognized
« on: February 12, 2019, 05:40:20 am »
There is this compilation error in my project. It uses wxWidgets version 3.0.3, and is compiled by GCC in Ubuntu 8.04.

Code
/opt/wx/3.0/include/wx-3.0/wx/dlimpexp.h|20|error: expected class-name before ‘__attribute__’|

This error appears on the second of these two lines in the file dlimpexp.h:

Code
#    define WXEXPORT __attribute__ ((visibility("default")))
#    define WXIMPORT __attribute__ ((visibility("default")))

This error means, as I understand it, that the "__attribute__" token is not recognized as a GCC attribute, but instead should be preceded with a class name to define what it is. Why it is that  __attribute__ is undefined in the second line above, and seems to be defined in the second is a mystery to me. Yet the second line above is line number 20 in dlimpexp.h, and is where the error is indicated.

I also can't figure why there would be an error such as this in a macro definition, which is supposed simply replace every instance of "WXIMPORT" in the source code with what follows in its line.

This file is part of the wxWidgets 3.0.3 package I compiled on my computer.
« Last Edit: February 12, 2019, 10:04:33 am by spflanze »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: __attribute__ Not Recognized
« Reply #1 on: February 12, 2019, 11:40:18 am »
We give no support for compiler or wxWidgets related question in this forum, because codeblocks is not a compiler...

Offline spflanze

  • Almost regular
  • **
  • Posts: 134
Re: __attribute__ Not Recognized
« Reply #2 on: February 13, 2019, 12:58:20 am »
After looking at the other error message lines I find the error is not in line 20 of dlimpexp.h where the macro is defined. It is instead everywhere this macro is expanded elsewhere in code. These two macros are defined only if the WXUSINGDLL is defined, the IDE code edtor's highlighting shows it is defined. But I am not not able to find where.  Right clicking and selecting "Find declaration" does not find it. A project wide search for "WXUSINGDLL" does not find it.

It has to be defined in the Code::Blocks IDE somewhere. But I have not been able to find it. Where is this defined?

Offline sodev

  • Regular
  • ***
  • Posts: 497
Re: __attribute__ Not Recognized
« Reply #3 on: February 13, 2019, 01:34:22 am »
It gets defined by
Code
wx-config --cflags
because you use wxWidgets as shared library :).

Apparently you had this before https://forums.wxwidgets.org/viewtopic.php?t=44808, how was it solved back then? Most probably a compiler configuration difference, you compile your application with different, incompatible settings than wxWidgets.

There is this compilation error in my project. It uses wxWidgets version 3.0.3, and is compiled by GCC in Ubuntu 8.04.
In your other thread you were using Ubuntu 18.04, if this is not a typo, it might be that the ancient GCC of Ubuntu 8.04 indeed does not understand __attribute__ ;D

Offline spflanze

  • Almost regular
  • **
  • Posts: 134
Re: __attribute__ Not Recognized
« Reply #4 on: February 13, 2019, 11:06:59 am »
It is Ubuntu 18.04.

I do not recall how I solved this earlier.

This project is migrated from Windows 7 because I need Valgrind. This project was transferred from Windows 7 to Ubuntu. I suspect that is trouble. I have created a new project in Ubuntu, and transferred all the files into the new project. But this did not solve the compilation problem I opened this thread for.

Given these errors, I think a shared library is also trouble. I am going to try static wxWidgets.


Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: __attribute__ Not Recognized
« Reply #5 on: February 14, 2019, 04:40:09 pm »
beside this being the wrong place to ask this kind of question i do not think that the compiler does not understand the __attribute__ bit, but the bit before the __attribute__ part.... There is some class as return value that is not defined or declared...

Quote
This project is migrated from Windows 7 because I need Valgrind. This project was transferred from Windows 7 to Ubuntu. I suspect that is trouble. I have created a new project in Ubuntu, and transferred all the files into the new project. But this did not solve the compilation problem I opened this thread for.
Of course you can not use the same project.... there are tons of defines in the windows project file that are not supported or wrong on linux.
If you have a compiling problem follow this faq:
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

Offline spflanze

  • Almost regular
  • **
  • Posts: 134
Re: __attribute__ Not Recognized
« Reply #6 on: February 16, 2019, 07:37:18 am »
I started this thread in this forum because I did not know whether this was a Code::Blocks problem or a wxWidgets problem.

The idea of wxWidgets is to be cross platform. A migration from Windows 7 to Ubuntu is supposed to be easy to do.

There are more things I have noticed. The error happens in the second define statement in this snippet from dlimpexp.h:

Code
#if defined(HAVE_VISIBILITY)
#    define WXEXPORT __attribute__ ((visibility("default")))
#    define WXIMPORT __attribute__ ((visibility("default")))
#elif defined(__WINDOWS__)

Note that the first define line is nearly identical to the second. Only the name of the macro is different. When, as a test, I changed the name from WXIMPORT to WXIMPORTX the error on that line disappeared (there were many other errors elsewhere of course). There is something going on with the name WXIMPORT. Anyone know what?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: __attribute__ Not Recognized
« Reply #7 on: February 16, 2019, 07:54:25 am »
If you think it is not a user error problem; post a full build log in code tags!

Note: I have no idea why you think it is a CB Problem; please state why you think so.

Edit: Do you realize you gave reasons for thinking it is a Compiler issue and reasons for thinking it is an wxWidgets issue.
But, no reason for thinking it is a CB issue!

Tim S.
« Last Edit: February 16, 2019, 08:18:35 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline sodev

  • Regular
  • ***
  • Posts: 497
Re: __attribute__ Not Recognized
« Reply #8 on: February 16, 2019, 08:13:57 am »
wxWidgets is cross platform, the compiler settings to make that magic happen however are not. These two macros do look quite different on the windows side because dll works different than so.

Without the build log, especially the full compiler line, this is just pure crystal ball we can do.

Offline spflanze

  • Almost regular
  • **
  • Posts: 134
Re: __attribute__ Not Recognized
« Reply #9 on: February 16, 2019, 08:31:10 pm »
The Build Log and Build messages are attached. The entire project can be downloaded from: http://www.mediafire.com/file/hi6bs180ihy0p8f/TIA_Designer_2019-02-16.zip/file

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: __attribute__ Not Recognized
« Reply #10 on: February 16, 2019, 10:01:22 pm »
Please learn to use code tags!
Next time try attaching the CB Project (it may need zipped)

Please try to build a wxWidgets hello world type CB project on Linux before doing a 390 MB size project!

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

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: __attribute__ Not Recognized
« Reply #11 on: February 16, 2019, 10:04:24 pm »
Attached Zipped CB Project
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: __attribute__ Not Recognized
« Reply #12 on: February 16, 2019, 10:12:02 pm »
Code
class WXDLLIMPEXP_CORE wxComboBoxDataFile : public WXDLLIMPEXP_CORE wxComboBox

Why do you think the second WXDLLIMPEXP_CORE in your file Utilities.h is needed?

Edit2/3: The first WXDLLIMPEXP_CORE may or may not be needed; the second WXDLLIMPEXP_CORE I have great doubt is needed or is correct to have.

Edit1: Build log snippet added below.
Code
include/Utilities.h:256:52: note: in expansion of macro ‘WXDLLIMPEXP_CORE’
 class WXDLLIMPEXP_CORE wxComboBoxDataFile : public WXDLLIMPEXP_CORE wxComboBox

Tim S.
« Last Edit: February 16, 2019, 10:47:37 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline spflanze

  • Almost regular
  • **
  • Posts: 134
Re: __attribute__ Not Recognized
« Reply #13 on: February 17, 2019, 11:41:39 pm »
Thank you for this answer. The WXDLLIMPEXP_CORE macro after the public keyword is the error's cause. Once removed this and all similar derived class declarations the compile was successful.

The original expectation was the parent class would have to appear in the line that creates the derived class in the same way the parent class was declared. In Windows 7 doing so did not trigger an error and compiled.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: __attribute__ Not Recognized
« Reply #14 on: February 18, 2019, 09:13:20 am »
In Windows 7 doing so did not trigger an error and compiled.
probably because the macro expands to an empty macro on windows.
Always read the whole error message and all the "notes" that come with it. Do NOT think that the line where the error is flagged is the line where the error is. Most of the time it is in the last note line of the error message.

[EDIT:] This could have been solved after the first post, if you post the full rebuild log in the first message the next time ;), or at least after someone pointed to it