Community
Participate
Working Groups
Build Identifier: 20110615-0604 If you include both unistd.h and then getopt.h (in that order) and then import the project, Eclipse will claim that getopt_long() is undefined. The only solution is to change the include order, delete the project, and re-import it. Reproducible: Always Steps to Reproduce: 1. Create a folder in your workspace and a file in the folder called main.cpp. 2. In a different text editor, enter the following into main.cpp: #include <unistd.h> #include <getopt.h> static struct option long_options[] = { {0, 0, 0, 0} }; int main(int argc, char *argv[]) { int option_index = 0; int c = getopt_long(argc, argv, "", long_options, &option_index); return 0; } 3. Go to File > Import > Existing Code as Makefile Project 4. Type the location of the folder created in step 1 5. Select the Linux GCC toolchain 6. Open main.cpp 7. Observe that usage of getopt_long() is considered erroneous despite that the source builds without issue. 8. Swap the order of the includes in main.cpp and observe error does not disappear 9. Delete the project and repeat steps 3-6. Observe that Eclipse now understands getopt_long() 10. Swap order of includes again. 11. Observe that Eclipse no longer complains, even with original include order.
I cannot reproduce the issue, it depends on the system includes. Most likely it goes away if you add getopt.h to the list of files to index up front. You can do so in the indexer preferences or on project level.
No response from submitter.
(In reply to comment #1) > goes away if you add getopt.h to the list of files to index up front I have a similar problem here (on Linux with gcc 4.6), include order doesn't matter. Adding getopt.h to the indexer as suggested solved it for me.
I too have a similar problem on Ubuntu with gcc 4.5.2. Adding getopt.h to the indexer solved the problem for me.
I am running Ubuntu 12.04 with g++ 4.6.3 and Eclipse CDT Indigo. I had the same problem -- which was also fixed by adding getopt.h to the indexed up front list.